下面是几条设置语句:
1)setAnimationDuration
2)setAnimationCurve
3)setAnimationTransition
[welcomeController viewWillAppear:YES];
[foodlistController viewWillDisappear:YES];
... ...
[foodlistController viewDidDisappear:YES];
[welcomeController viewDidAppear:YES];
怎么理解这些语句的作用呢?我们回想一下之前提过的delegate
举个例子,如果当前的view
以下来自---http://www.cnblogs.com/ulihj/archive/2011/01/26/1945336.html
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html
[UIView setAnimationDuration: 1.0 ];
[UIView setAnimationCurve:UIViewAnimationEaseInOut
// Make the animatable changes.
firstView.alpha = 0.0 ;
secondView.alpha = 1.0 ;
// Commit the changes and perform the animation.
[UIView commitAnimations];
- (IBAction)showHideView:(id)sender
{
[UIView beginAnimations: @" ShowHideView " context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEase
[UIView setAnimationDuration: 1.0 ];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelec
// Make the animatable changes.
thirdView.alpha = 0.0 ;
// Commit the changes and perform the animation.
[UIView commitAnimations];
}
// Called at the end of the preceding animation.
- ( void )showHideDidStop:(NSString * )animationID finished:(NSNumber * )finished context:( void * )context
{
[UIView beginAnimations: @" ShowHideView2 " context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEase
[UIView setAnimationDuration: 1.0 ];
[UIView setAnimationDelay: 1.0 ];
thirdView.alpha = 1.0 ;
[UIView commitAnimations];
}
接下去要讲view transition的动画效果,就是常见的那种翻页的效果,老版本的写法是这样的:
[UIView setAnimationTransition:
UIViewAnimationTransitio
forView:self.view cache:YES];
[blueViewController viewWillAppear:YES];
[yellowViewController viewWillDisappear:YES];
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex: 0 ];
[yellowViewController viewDidDisappear:YES];
[blueViewController viewDidAppear:YES];
在IOS4.0 之前,要实现view之间切换的动画效果你必须使用父view,然后切换子view,只有子view的效果才能出现动画,所以你看setAnimationTranistion里forView里写的父view。
4.0之后,可以这么写:
toView:(self._view2)
duration: 1.0
options:UIViewAnimationOptionTra
completion: ^ (BOOL finished) {
}
];