226
人物
iOS添加到購物車的簡單動畫效果
#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
在動畫完成後,更新顯示購物車中的商品種類數
最後更新:2017-04-03 12:56:20