现在的位置: 首页 > 综合 > 正文

UIView的动画

2012年07月30日 ⁄ 综合 ⁄ 共 1523字 ⁄ 字号 评论关闭

一种方法是利用封装了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动画小记

【上篇】
【下篇】

抱歉!评论已关闭.