ios 动画效果CATransition笔记

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

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

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

- (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) forControlEvents: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





  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值