我正在学习iOS并通过一个例子 - 我最理解的。这是一些代码,我将跟进一个问题:
- (IBAction) switchViews:(id)sender{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.yellowViewController.view.superview == nil) {
if (self.yellowViewController == nil) {
YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
self.yellowViewController = yellowController;
[yellowController release];
}
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 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];
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.yellowViewController.view.superview == nil) {
if (self.yellowViewController == nil) {
YellowViewController *yellowController = [[YellowViewController alloc] initWithNibName:@"YellowView" bundle:nil];
self.yellowViewController = yellowController;
[yellowController release];
}
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 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];
这是我的理解。动画很清晰。
我们正在检查是否显示了yellowViewController。如果没有,那么我们检查并查看它是否已实例化。如果没有,我们实例化它然后显示它,首先从SuperView中删除blueViewController。
到目前为止一切都很好。
这是我不明白的原因 - 为什么要做以下事情:
[blueViewController viewWillAppear:YES];
在我看来,我们应该消除blueViewController而不是黄色。
我真的很感激解释。感谢。
答案 0 :(得分:0)
您不应该自己进行这些调用,它们是由iOS框架自动生成的。因此,您的所有viewWill…
和viewDid…
来电都是不必要的,可以删除。