iOS添加到购物车的简单动画效果
2015-12-03 12:55
567 查看
[objc] view plaincopyprint?
[objc] view plaincopyprint?
#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
在动画完成后,更新显示购物车中的商品种类数
[objc] view plaincopyprint?
#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
在动画完成后,更新显示购物车中的商品种类数
相关文章推荐
- iOS开发之多媒体API
- iOS多线程编程技术之NSThread、Cocoa NSOperation、GCD
- iOS开发之GCD使用总结
- iOS 屏幕适配,autoResizing autoLayout和sizeClass图文详解
- nagios下批量添加hosts.cfg脚本
- IOS中NSUserDefaults的用法(轻量级本地数据存储)
- iOS单例
- iOS 调用js方法,去除HTML标签
- IOS缓存机制详解
- iOS Quartz笔记
- iOS9 左上角蓝色小圆点的出现 解决方法
- iOS管理文件和目录
- 关于iOS远程推送原理步骤
- iOS页面间传值的方式(Delegate/NSNotification/Block/NSUserDefault/单例)
- iOS 笔记-删除插件的方法
- IOS 序列化与反序列化NSKeyedUnarchiver
- [iOS进阶]多线程中的内存控制
- ios NSURLSession使用说明及后台工作流程分析
- iOS开发-XCode常用快捷键整理
- iOS8 沙盒路径变化特性