您的位置:首页 > 移动开发 > IOS开发

ios 动画效果CATransition笔记

2015-12-16 11:00 561 查看
 初学ios开发,很多概念还不清楚,所以只有边学边做例子。又怕学了后面忘了前面,因此用自己的博客来纪录自己的学习历程,也是对自己学习不要懈怠做个监督。

    刚学ios做动画效果。因为ios封装得很好,实现ios的漂亮动画效果也很简单,却因为我自己的粗心落了一个字母 导致纠结了一天,这个教训必须记住,同时也懂得了调试技能在编程里地位也是非常重要的存在。

   实现ios动画有两种方法:一种UIView层面的,一种是使用CATransition.

[objc] view
plaincopy





- (void)viewDidLoad  

{  

    [super viewDidLoad];  

    // Do any additional setup after loading the view.  

      

    UIView *redView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  

    redView.backgroundColor = [UIColor redColor];  

    [self.view addSubview:redView];  

      

    UIView *yellowView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  

    yellowView.backgroundColor = [UIColor yellowColor];  

    [self.view addSubview:yellowView];  

      

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  

    [button setTitle:@"改变1" forState:UIControlStateNormal];  

    button.frame = CGRectMake(10, 10, 300, 40);  

    [button addTarget:self action:@selector(changeUIView1) forControlEvents:UIControlEventTouchUpInside];  

    [self.view addSubview:button];  

      

  

      

    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];  

    [button2 setTitle:@"改变2" forState:UIControlStateNormal];  

    button2.frame = CGRectMake(10, 120, 300, 40);  

    [button2 addTarget:self action:@selector(changeUIView2) forControlEvent
f1f0
s:UIControlEventTouchUpInside];  

    [self.view addSubview:button2];  

}  

-(void) changeUIView1{  

    [UIView beginAnimations:@"animation" context:nil];  

    [UIView setAnimationDuration:1.0f];  

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];  

    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0  ];  

    [UIView commitAnimations];  

}  

  

-(void) changeUIView2{  

   CATransition *transition = [CATransition animation];  

    transition.delegate = self;  

    transition.duration = 2.0f;  

    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];  

    transition.type = kCATransitionPush;  

    transition.type = @"pageCurl"  ;//另一种设置动画效果方法  

    transition.subtype = kCATransitionFromBottom;  

    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];  

    [self.view.layer addAnimation:transition forKey:@"animation"];  

}  

调用CATransition需要在frameworks中添加QuartzCore.framework,在.h文件中加入  #import <QuartzCore/QuartzCore.h>

setType:有四种类型:

    

    kCATransitionFade                   //交叉淡化过渡

    kCATransitionMoveIn               //移动覆盖原图

    kCATransitionPush                    //新视图将旧视图推出去

    kCATransitionReveal                //底部显出来

另一种设置方法

   pageCurl     //向上翻一页

    pageUnCurl   //向下翻一页

    rippleEffect   //滴水效果

    suckEffect     //收缩效果,如一块布被抽走

    cube       //立方体效果

    oglFlip      //上下翻转效果

setSubtype:有四种类型:

    

    kCATransitionFromRight;

    kCATransitionFromLeft(默认值)

    kCATransitionFromTop;

    kCATransitionFromBottom
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: