- #pragma mark - 添加到购物车的动画效果
- // huangyibiao
- - (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;
- }
frame参数是按钮的frame,也就是原来所在父视图上的Frame
这里会将原来的frame转换成window上的frame
在动画完成后,更新显示购物车中的商品种类数