UIView的动画
一种方法是利用封装了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];
再传送两个网址,讲的详细些: