我正在构建一个iPad应用程序,并希望通过按下按钮将我的一个子视图切换为另一个。我一直在阅读文档和本指南:
View Controllers: How to switch between views programmatically?
但是我一直都会遇到错误并且动画并没有真正发生,视图会立即切换。
我会在下面粘贴一些代码以供上下文使用。我有一个主视图,其中包含一个子视图。在子视图中,还有另一种观点。我想将另一个视图与另一个视图交换。
self.settingsViewController = [[GHPSettingsViewController alloc] initWithNibName: @"GHPSettingsViewController" bundle: nil andParent: self];
UIView *outerView = [self.containingView viewWithTag:0];
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration: 100.25f];
[UIView setAnimationDuration: UIViewAnimationCurveEaseInOut];
if (self.settingsViewController.view.superview == nil) {
// Flip Out Old View
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.containingView cache:YES];
[self.settingsViewController viewWillAppear: YES];
[outerView removeFromSuperview];
[self.containingView insertSubview: self.settingsViewController.view atIndex: 0];
[self.settingsViewController viewDidAppear: YES];
}
[UIView commitAnimations];