您的位置:首页 > 其它

仿淘宝加入购物车动画

2016-08-01 16:43 260 查看
#pragma mark - 动画(加入购物车)
- (void)shopBagAni
{
CGRect startRect;
CGRect endRect;
CGPoint imgPoint;
//最右上角购物车图标位置
imgPoint = [self.view convertPoint:sizeView.img_dress.center fromView:sizeView.img_dress];
startRect = CGRectMake(imgPoint.x, imgPoint.y, sizeView.img_dress.bounds.size.width,sizeView.img_dress.bounds.size.height);
endRect = CGRectMake(ScreenWidth-30,45, 0.0f, 0.0f);

UIImageView *imgView_animation = [[UIImageView alloc]init];
[imgView_animation setFrame:startRect];
[imgView_animation setImage:sizeView.img_dress.image];
[imgView_animation setBackgroundColor:COLOR_C_333333];
imgView_animation.center = startRect.origin;
[self.view addSubview:imgView_animation];

[UIView beginAnimations:@"addToShopBagAnimation" context:(__bridge void *)(imgView_animation)];
[UIView setAnimationDuration:0.7f];
//接受动画代理
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[imgView_animation setFrame:endRect];
//提交动画
[UIView commitAnimations];
}
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
if ([animationID isEqualToString:@"addToShopBagAnimation"]) {
// 触发更新购物车上的小圆圈与加入购物车逻辑
//[commFun refreshBadge:self.tabBarController];
[[AlertHandler singleton]showToastHUD:self.view message:@"商品成功加入购物袋" sleepTime:1.5];
[[NSNotificationCenter defaultCenter]postNotificationName:@"removeView" object:nil];
}
}

效果大约如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: