UIView的动画

本文介绍了两种实现iOS视图过渡动画的方法:一种是使用UIView类方法实现简单的过渡效果;另一种是利用CATransition实现更复杂的过渡效果,提供更多控制选项。

一种方法是利用封装了CATransition的UIView类方法来实现,这方法简单但效果少。

    //把子视图从父视图里删除的动画效果
[UIView beginAnimations:@"animation_" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

UIViewController * coming = [[UIViewController alloc] init];
UIViewController * going = [[UIViewController alloc] init];
coming.view = self.view.superview;
going.view = self.view;

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

[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[going.view removeFromSuperview];
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];

[UIView commitAnimations];

[coming release];
[going release];

另一种方法是直接利用CATransition,复杂点但效果多些,可控性强,推荐.

//子视图从父视图里删除的动画效果
CATransition * animation = [CATransition animation];
[animation setRemovedOnCompletion:NO];
[animation setDuration:.25];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];

UIViewController * coming = [[UIViewController alloc] init];
UIViewController * going = [[UIViewController alloc] init];
coming.view = self.view.superview;
going.view = self.view;

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

[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[going.view removeFromSuperview];
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];

[self.view.superview.layer removeAnimationForKey:@"animation_"];

[coming release];
[going release];

 

再传送两个网址,讲的详细些:

CATransition的动画效果类型及实现方法

UIView动画小记




转载于:https://www.cnblogs.com/xiaouisme/archive/2012/02/22/2363308.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值