码迷,mamicode.com
首页 > 移动开发 > 详细

iOS添加到购物车的简单动画效果

时间:2015-12-03 13:45:27      阅读:415      评论:0      收藏:0      [点我收藏+]

标签:

  1.   

 

  1. #pragma mark - 添加到购物车的动画效果  
  2. // huangyibiao  
  3. - (void)addAnimatedWithFrame:(CGRect)frame {  
  4.   // 该部分动画 以self.view为参考系进行  
  5.   frame = [[UIApplication sharedApplication].keyWindow  convertRect:frame fromView:self.RFcell.headBtn];  
  6.   UIButton *move = [[UIButton alloc] initWithFrame:frame];  
  7.   [move setBackgroundColor:UIColorFromRGB(0xFFA215)];  
  8.   [move setTitle:self.RFcell.headBtn.currentTitle forState:UIControlStateNormal];  
  9.   [move setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];  
  10.   move.contentMode = UIViewContentModeScaleToFill;  
  11.   [[UIApplication sharedApplication].keyWindow addSubview:move];  
  12.   // 加入购物车动画效果  
  13.   [UIView animateWithDuration:1.2 animations:^{  
  14.     move.frame = CGRectMake(320 - frame.size.width  - 20, 24,  
  15.                             frame.size.width, frame.size.height);  
  16.   } completion:^(BOOL finished) {  
  17.     [move removeFromSuperview];  
  18.     if (self.cartCategoriesLabel == nil) {  
  19.       self.cartCategoriesLabel = [[UILabel alloc] initWithFrame:CGRectMake((16 - 8) / 2, (16 - 8) / 2, 8, 8)];  
  20.       self.cartCategoriesLabel .textColor = [UIColor whiteColor];  
  21.       self.cartCategoriesLabel .backgroundColor = [UIColor clearColor];  
  22.       self.cartCategoriesLabel .textAlignment = NSTextAlignmentCenter;  
  23.       self.cartCategoriesLabel .font = [UIFont systemFontOfSize:9];  
  24.       UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 8, 16, 16)];  
  25.       imgView.image = [UIImage imageNamed:@"news"];  
  26.       [imgView addSubview:self.cartCategoriesLabel];  
  27.       [self.cartButton addSubview:imgView];  
  28.     }  
  29.     self.cartCategoriesLabel .text = [NSString stringWithFormat:@"%d", _cartCategories.count];  
  30.   }];  
  31.     
  32.   return;  
  33. }  



 

 

frame参数是按钮的frame,也就是原来所在父视图上的Frame

这里会将原来的frame转换成window上的frame

在动画完成后,更新显示购物车中的商品种类数

iOS添加到购物车的简单动画效果

标签:

原文地址:http://www.cnblogs.com/fengmin/p/5015856.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!