iOS - 转场动画
2016-04-06 15:57
393 查看
先上效果图
①还未旋转之前
②旋转中
③旋转后
如图所示:
此处动画为3D效果 贴上封装好的方法(方法有二)
CATransform3DMakeRotation(M_PI, 0, 1, 0);
第一个参数:以(x,y,z)的空间向量旋转到哪个角度
M_PI 3.14159265358979323846264338327950288 /* pi */
M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
注意点:
view.transform 是二维旋转
view.layer.transform 图层可三维旋转
总之大家试试吧 谢谢你能看完!
①还未旋转之前
②旋转中
③旋转后
如图所示:
此处动画为3D效果 贴上封装好的方法(方法有二)
#import <UIKit/UIKit.h> @interface TransView : UIView /** 二维动画旋转*/ -(void)transition2DwithRotation:(CGFloat) transform Duration:(CGFloat)time; /** 三维动画旋转*/ -(void)transition3DwithRotation:(CATransform3D)transform3D Duration:(CGFloat)time finishImage:(UIImage *)finishImage hadRotate:(BOOL)ret; @end
#import "TransView.h" @implementation TransView -(instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { self.frame = frame; } return self; } /** 二维动画旋转*/ -(void)transition2DwithRotation:(CGFloat) transform Duration:(CGFloat)time{ //让view旋转 [UIView animateWithDuration:time animations:^{ self.transform = CGAffineTransformMakeRotation(transform); } completion:^(BOOL finished) { }]; } /** 三维动画旋转*/ -(void)transition3DwithRotation:(CATransform3D)transform3D Duration:(CGFloat)time finishImage:(UIImage *)finishImage hadRotate:(BOOL)ret{ //方法一 [UIView animateWithDuration:time animations:^{ self.layer.transform = transform3D; } completion:^(BOOL finished) { if (finishImage) { self.backgroundColor = [UIColor colorWithPatternImage:finishImage]; } [UIView animateWithDuration:time animations:^{ self.layer.transform = CATransform3DMakeRotation(M_PI, 0, 1, 0); }]; }]; //方法二 // [UIView transitionWithView:self duration:time options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{ // if (finishImage) { // //默认图片 // self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"user_default"]]; // } // } completion:^(BOOL finished) { // // if (finishImage) { // //旋转后的图片 // self.backgroundColor = [UIColor colorWithPatternImage:finishImage]; // } // }); // // // }]; }
CATransform3DMakeRotation(M_PI, 0, 1, 0);
第一个参数:以(x,y,z)的空间向量旋转到哪个角度
M_PI 3.14159265358979323846264338327950288 /* pi */
M_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
M_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
M_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
M_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
注意点:
view.transform 是二维旋转
view.layer.transform 图层可三维旋转
总之大家试试吧 谢谢你能看完!
相关文章推荐
- IOS 把格式化的字符串转换成字典类型 NSString 转换成 NSDictonary
- Xcode memory usage 不显示
- iOS聊天界面cell从下至上滚动
- IOS-TextField控件详解
- ios ffmpeg 编译
- iOS开发设置状态栏字体颜色
- 获取设备上的调试信息与崩溃日志分析
- ios开发中常用的函数和常数
- IOS ZipArchive
- iOS编码规范精简版-根据apple、google等规范总结而来
- iOS 本地缓存 归档数据模型化 .m
- IOS 自定义push和pop动画
- ios CocoaPods安装和使用
- 相机的授权 同样适用于扫一扫前的授权判断
- iOS 常用工具 加密规则
- iOS主要设备支持的视频格式
- iOS 定位
- iOS-字符串转化成NSDate类型 计算与当前时间的相差 月数 天数
- iOS 本地缓存 归档数据模型化
- iOS-获取的NSDate date时间与实际相差8个小时解决方案