博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
为UIView视图切换添加动画效果
阅读量:4967 次
发布时间:2019-06-12

本文共 2693 字,大约阅读时间需要 8 分钟。

我们定义了一个动画类来实现视图切换的动画效果,这个类只包含一个类方法,可直接调用,具体代码如下:

头文件:

#import 
@interface ViewAnimation : NSObject/*============================页面切换的方法============================== View1 表示当前页面 View2 表示目标页面 VC 两个view所在的viewController 共有12种动画效果和四个动画方向,这里采用随机挑选动画和方向的方案======================================================================*/+(void)TransView1:(UIView*)v1 View2:(UIView*)v2 VC:(UIViewController*)vc;@end

 体文件:

#import "ViewAnimation.h"#import 
#define kDuration 0.4 // 动画效果持续时间(秒)@implementation ViewAnimation// 页面切换的方法+(void)TransView1:(UIView*)v1 View2:(UIView*)v2 VC:(UIViewController *)vc;{ CATransition *animation = [CATransition animation]; animation.delegate = self; animation.duration = kDuration; animation.timingFunction = UIViewAnimationCurveEaseInOut; switch (rand()%11) { case 1: animation.type = kCATransitionFade; break; case 2: animation.type = kCATransitionPush; break; case 3: animation.type = kCATransitionReveal; break; case 4: animation.type = kCATransitionMoveIn; break; case 5: animation.type = @"cube"; break; case 6: animation.type = @"suckEffect"; break; case 7: animation.type = @"oglFlip"; break; case 8: animation.type = @"rippleEffect"; break; case 9: animation.type = @"pageCurl"; break; case 10: animation.type = @"pageUnCurl"; break; case 11: animation.type = @"cameraIrisHollowOpen"; break; case 0: animation.type = @"cameraIrisHollowClose"; break; default: animation.type = kCATransitionMoveIn; break; } switch (rand()%3) { case 0: animation.subtype = kCATransitionFromLeft; break; case 1: animation.subtype = kCATransitionFromBottom; break; case 2: animation.subtype = kCATransitionFromRight; break; case 3: animation.subtype = kCATransitionFromTop; break; default: animation.subtype = kCATransitionFromRight; break; } [vc.view addSubview:v2]; NSInteger x1 = [[vc.view subviews]indexOfObject:v1]; NSInteger x2 = [[vc.view subviews]indexOfObject:v2]; [vc.view exchangeSubviewAtIndex:x1 withSubviewAtIndex:x2]; [[vc.view layer]addAnimation:animation forKey:@"animation"];}@end

 

转载于:https://www.cnblogs.com/fizix100/p/3700062.html

你可能感兴趣的文章
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>
【BZOJ】2959: 长跑(lct+缩点)(暂时弃坑)
查看>>
iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
查看>>
toad for oracle中文显示乱码
查看>>
SQL中Group By的使用
查看>>
错误org/aopalliance/intercept/MethodInterceptor解决方法
查看>>
两个表格中数据不用是一一对应关系--来筛选不同数据,或者相同数据
查看>>
客户数据库出现大量cache buffer chains latch
查看>>
機械の総合病院 [MISSION LEVEL: C]
查看>>
实战练习细节(分行/拼接字符串/字符串转int/weak和copy)
查看>>
Strict Standards: Only variables should be passed by reference
查看>>
hiho_offer收割18_题解报告_差第四题
查看>>
AngularJs表单验证
查看>>
静态方法是否属于线程安全
查看>>
02号团队-团队任务3:每日立会(2018-12-05)
查看>>
SQLite移植手记1
查看>>
js05-DOM对象二
查看>>
mariadb BINLOG_FORMAT = STATEMENT 异常
查看>>
C3P0 WARN: Establishing SSL connection without server's identity verification is not recommended
查看>>
iPhone在日本最牛,在中国输得最慘
查看>>