仿淘宝加入购物车动画

来源:互联网 发布:真实交友软件 编辑:程序博客网 时间:2024/04/29 07:22
#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];    }}

效果大约如下:


3 0