我在学习《Beginning iPhone 4 Development Exploring the iOS SDK》(中文版的名称为《iPhone 4与iPad开发基础教程》)这本书
有一个关于第6章View Switcher这个例子中 - (IBAction)switchViews:(id)sender 这个函数中处理动画flip效果的一个问题
请看代码
- (IBAction)switchViews:(id)sender
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.yellowViewController.view.superview == nil) //如果要换入黄色view
{
。。。。。 //如果没有则创建
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES]; //设定动画方式
[blueViewController viewWillAppear:YES]; //不明白这里为什么是 蓝色的将要出现,而不是黄色视图将要出现,(以下同)
[yellowViewController viewWillDisappear:YES];
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex:0]; //去掉蓝色的,换入黄色的view
[yellowViewController viewDidDisappear:YES];
[blueViewController viewDidAppear:YES];
}
。。。。
}
以上内容是我在如下地址引用的:
http://www.cocoachina.com/bbs/simple/?t88356.html
由于我也遇到了同样的问题,所以问题我也不再描述。Cocoa China博客园升级中。。。
1、我在下面地址中找到了《Beginning iPhone 4 Development 》的源代码:
https://github.com/ronco/Beginning-iPhone-4-Development
viewWillAppear:
Notifies the view controller that its view is about to be added to a view hierarchy.
Parameters
- animated
-
If
YES
, the view is being added to the window using an animation.
Discussion
This method is called before the receiver’s view is about to be added to a view hierarchy and before any animations are configured for showing the view. You can override this method to perform custom tasks associated with displaying the view. For example, you might use this method to change the orientation or style of the status bar to coordinate with the orientation or style of the view being presented. If you override this method, you must call super
at some point in your implementation.
For more information about the how views are added to view hierarchies by a view controller, and the sequence of messages that occur, see“Responding to Display-Related Notifications”.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
UIViewController.h