详解IOS图层转场动画

2025-05-29 0 82

CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点
UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果
属性解析:

  • type:动画过渡类型
  • subtype:动画过渡方向
  • startProgress:动画起点(在整体动画的百分比)
  • endProgress:动画终点(在整体动画的百分比)

具体代码:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70
/* 过渡效果

fade //交叉淡化过渡(不支持过渡方向) kCATransitionFade

push //新视图把旧视图推出去 kCATransitionPush

moveIn //新视图移到旧视图上面 kCATransitionMoveIn

reveal //将旧视图移开,显示下面的新视图 kCATransitionReveal

cube //立方体翻滚效果

oglFlip //上下左右翻转效果

suckEffect //收缩效果,如一块布被抽走(不支持过渡方向)

rippleEffect //滴水效果(不支持过渡方向)

pageCurl //向上翻页效果

pageUnCurl //向下翻页效果

cameraIrisHollowOpen //相机镜头打开效果(不支持过渡方向)

cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)

*/

/* 过渡方向

kCATransitionFromRight

kCATransitionFromLeft

kCATransitionFromBottom

//转场动画--》是针对某个view的图层进行转场动画

#import "ViewController.h"

#import <QuartzCore/QuartzCore.h>

@interface ViewController ()

{

UIView *_lastview;

BOOL flag;

}

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

flag=true;

UIView *view=[[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];

view.backgroundColor=[UIColor redColor];

[self.view addSubview:view];

[view release];

_lastview=view;

// Do any additional setup after loading the view, typically from a nib.

}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

if(flag){

_lastview.backgroundColor=[UIColor yellowColor];

flag=false;

}

else{

_lastview.backgroundColor=[UIColor redColor];

flag=true;

}

//转场动画--就是对某个view进行动画切换。

//1:如果是控制器之间的切换,其实window上view进行切换

CATransition *transion=[CATransition animation];

//设置转场动画的类型

transion.type=@"pageCurl";

//设置转场动画的方向

transion.subtype=@"fromLeft";

//把动画添加到某个view的图层上

[self.view.layer addAnimation:transion forKey:nil];

}

控制器直接切换动画

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14
UIApplication *app=[UIApplication sharedApplication];

AppDelegate *dd=app.delegate;

MyViewController *my=[[MyViewController alloc] init];

//切换根控制器,其实把视图控制器的view在window上切换。所以在转场动画要作用在window上

dd.window.rootViewController=my;

CATransition *trans=[CATransition animation];

trans.type=@"pageCurl";

trans.subtype=@"fromTop";

[dd.window.layer addAnimation:trans forKey:nil];

[my release];

以上就是本文的全部内容,希望对大家的学习有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 详解IOS图层转场动画 https://www.kuaiidc.com/93158.html

相关文章

发表评论
暂无评论