最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
苹果开发之iOS加入购物车动画效果
时间:2022-06-25 23:40:27 编辑:袖梨 来源:一聚教程网
代码如下 | 复制代码 |
#pragma mark -购物篮按钮点击事件 -(void)shoppingCartButtonAction:(UIButton*)sender { if ([[userDef objectForKey:@"id"]isEqualToString:@"0"]) { [self showHUDTextOnly:@"请登录后,再进行操作" ]; return; } NSDictionary *parameters = @{ @"user_id":[userDef objectForKey:@"id"], @"gp_id":[NSString stringWithFormat:@"%@",[cell2Array[sender.tag - 101] objectForKey:@"gp_id"]], @"number" :@1 }; [self defaultRequestwithURL:KAddToCartURL withParameters:parameters withMethod:@"POST" withBlock:^(NSDictionary *dict, NSError *error){ if ([[dict objectForKey:kCode] integerValue]==1) { //该部分动画 以self.view为参考系进行 UIImageView *imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"button_hot_shopping-cart_red-1"]]; imageView.contentMode=UIViewContentModeCenter; imageView.frame = sender.bounds; imageView.hidden=YES; CGPoint point= sender.frame.origin; imageView.center=point; CALayer *layer=[[CALayer alloc]init]; layer.contents=imageView.layer.contents; layer.frame=imageView.frame; layer.opacity=1; [self.view.layer addSublayer:layer]; //动画 终点 都以sel.view为参考系 CGPoint endpoint= CGPointMake(SCREEN_WIDTH*7/10.0, SCREEN_HEIGHT - 22); UIBezierPath *path=[UIBezierPath bezierPath]; //动画起点 CGRect rect=[sender convertRect: sender.bounds toView:self.view]; CGPoint startPoint=CGPointMake(rect.origin.x +rect.size.width/2, rect.origin.y +rect.size.height/2); [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]; 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"]; //更新角标 [self cornerNumber]; }else { [self showHUDTextOnly:[dict objectForKey:kMessage]]; } }]; } |
相关文章
- 以闪亮之名店长体验流霞季怎么玩 缘溪临霞套装活动介绍 12-31
- 未定事件簿旧梦新生左然篇怎么玩 旧梦新生左然篇活动介绍 12-31
- 未定事件簿左然破浪远行怎么样 12-31
- 桃源深处有人家行医问诊怎么玩 12-31
- 恋与制作人跨年福利有哪些 恋与制作人跨年福利内容介绍 12-31
- 阴阳师协同对弈大乱斗怎么玩 阴阳师协同对弈大乱斗活动介绍 12-31