您的位置:首页 > 其它

加入购物车动画效果

2016-04-13 00:00 344 查看
一: 普通的frame的改变

(void)addAnimatedWithFrame:(CGRect)frame {
// 该部分动画 以self.view为参系进行
frame = [[UIApplication sharedApplication].keyWindow convertRect:frame fromView:self.RFcell.headBtn];
UIButton move = [[UIButton alloc] initWithFrame:frame];
[move setBackgroundColor:UIColorFromRGB(0xFFA215)];
[move setTitle:self.RFcell.headBtn.currentTitle forState:UIControlStateNormal];
[move setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
move.contentMode = UIViewContentModeScaleToFill;
[[UIApplication sharedApplication].keyWindow addSubview:move];
// 加入购物车动画效果
[UIView animateWithDuration:1.2 animations:^{
move.frame = CGRectMake(320 - frame.size.width - 20, 24,
frame.size.width, frame.size.height);
} completion:^(BOOL finished) {
[move removeFromSuperview];
if (self.cartCategoriesLabel == nil) {
self.cartCategoriesLabel = [[UILabel alloc] initWithFrame:CGRectMake((16 - 8) / 2, (16 - 8) / 2, 8, 8)];
self.cartCategoriesLabel .textColor = [UIColor whiteColor];
self.cartCategoriesLabel .backgroundColor = [UIColor clearColor];
self.cartCategoriesLabel .textAlignment = NSTextAlignmentCenter;
self.cartCategoriesLabel .font = [UIFont systemFontOfSize:9];
UIImageView imgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 8, 16, 16)];
imgView.image = [UIImage imageNamed:@"news"];
[imgView addSubview:self.cartCategoriesLabel];
[self.cartButton addSubview:imgView];
}
self.cartCategoriesLabel .text = [NSString stringWithFormat:@"%d", _cartCategories.count];
}]; return;
}

二:利用Bezier曲线

(void)showLikedFoodsAnimation:(NSNotification )notification { //get the location of label in table view NSValue value = notification.userInfo[@"position"]; CGPoint lbCenter = value.CGPointValue;//the image which will play the animation soon UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cm_center_discount"]]; imageView.contentMode = UIViewContentModeScaleToFill; imageView.frame = CGRectMake(0, 0, 20, 20); imageView.hidden = YES; imageView.center = lbCenter;//the container of image view CALayer *layer = [[CALayer alloc]init]; layer.contents = imageView.layer.contents; layer.frame = imageView.frame; layer.opacity = 1; [self.view.layer addSublayer:layer];CGPoint btnCenter = carButton.center; //动画 终点 都以sel.view为参系 CGPoint endpoint = [self.view convertPoint:btnCenter fromView:carBG]; UIBezierPath path = [UIBezierPath bezierPath]; //动画起点 CGPoint startPoint = [self.view convertPoint:lbCenter fromView:self.tableView]; [path moveToPoint:startPoint]; //贝塞尔曲线控制点 float sx = startPoint.x; float sy = startPoint.y; float ex = endpoint.x; float ey = endpoint.y; float x = sx + (ex - sx) / 3; float y = sy + (ey - sy) 0.5 - 400; CGPoint centerPoint=CGPointMake(x, y); [path addQuadCurveToPoint:endpoint controlPoint:centerPoint];//key frame animation to show the bezier path animation CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.path = path.CGPath; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; animation.duration = 0.8; animation.delegate = self; animation.autoreverses = NO; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; [layer addAnimation:animation forKey:@"buy"]; }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息