iOS 手机淘宝加入购物车动画分析
1、最终效果
仿淘宝动画
2、核心代码
_cartAnimView=[[UIImageView alloc] initWithFrame:CGRectMake(_propView.frame.size.height*0.025,_propView.frame.size.height* -0.025 , _propView.frame.size.height*0.2, _propView.frame.size.height*0.2)];
[self.view addSubview:_cartAnimView];
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 11.0 ];
rotationAnimation.duration = 1.0;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 0;
//这个是让旋转动画慢于缩放动画执行
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_cartAnimView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
});
[UIView animateWithDuration:1.0 animations:^{
_cartAnimView.frame=CGRectMake(self.screenWidth-55, -(self.screenHeight - CGRectGetHeight(self.view.frame) - 40), 0, 0);
} completion:^(BOOL finished) {
//动画完成后做的事
}];
3、动画分析
这个动画有两个动作,一个是旋转,一个是缩小。(更好的动画是增加一个:抛物线轨道)
基于分析,所以用核心动画组应该更好,以后有时间在做,或者有高手可以分享一下,谢谢!
这个实现的代码一定不是最好的,请大家多多指教,一起进步,我也在深入学习中,学好一点会再更新本文。
ps:淘宝的加入购物车动画相对我自己实现的更畅,分析发现,淘宝在点击加入购物车动作后,并没有先跟服务器请求加入购物车,而是动画后,返回到商品详情dmd消失后,后台才请求吧。这样动画就不用等待了。但这样的逻辑合理吗?我不清楚为什么这样做,有懂的请多指教!
4、其它动画
动画(1)
#### 核心代码
#pragma mark - 加入购物车动画
-(void)addAnimations
{
_cartAnimView=[[UIImageView alloc] initWithFrame:CGRectMake(_propView.frame.size.height*0.025,_propView.frame.size.height* -0.025 , _propView.frame.size.height*0.2, _propView.frame.size.height*0.2)];
[self.view addSubview:_cartAnimView];
[UIView animateWithDuration:1.0 animations:^{
_cartAnimView.frame=CGRectMake(self.screenWidth-55, -(self.screenHeight - CGRectGetHeight(self.view.frame) - 40), 0, 0);
_cartAnimView.transform = CGAffineTransformRotate(_cartAnimView.transform, M_PI_2);
} completion:^(BOOL finished) {
//动画完成后做的事
}];
}
相关文章
- iOS 开发之动画篇 - Transform和KeyFrame动画
- iOS-私有API与runtime
- ios CGRec用法
- ALAssetsLibrary-代码操作iOS相册资源
- IOS学习资源收集--关于动画的代码学习资源总汇(很棒的动画效果哦)
- IOS之UIImageView--小实例项目--带音效的拳皇动画
- iOS开发UI篇—ios应用数据存储方式(归档)
- IOS Masonry自动布局
- IOS runtime动态运行时二
- 【IOS-COCOS2D游戏开发之十八】解决滚屏背景/拼接地图有黑边(缝隙)/图片缩放后模糊透明/图片不清晰【2013年12月13日补充】/动画播放出现毛边以及禁止游戏中自动锁屏问题!
- 【IOS-COCOS2D游戏开发之二十二 】CCSPEED实现CCANIMATE动画进行时设置慢动作以及设置游戏加减速进行(塔防游戏必备)!
- iOS中 UITabBarController中自定义UITabBar
- iOS网络编程-MBProgressHUD等待指示器
- IOS毛玻璃效果
- 在Windows笔记本上调试运行在iOS设备上的前端应用
- Swift学习笔记(3)iOS 9 中的网络请求
- Android 10.0 Launcher3仿ios长按app图标实现抖动动画开始拖拽停止动画
- iOS开发 - NSScanner的使用方法
- iOS开发UI篇—懒载入
- Android 11.0 Launcher3仿ios长按app图标实现抖动动画开始拖拽停止动画