我有一个用户导航的 UINavigationController。将特定的 UIViewController 推送到导航堆栈时,导航栏中会出现一个“设置”按钮。当用户单击此按钮时,我想将当前视图/控制器(即屏幕上的所有内容,包括导航栏)翻转到设置视图。
所以我有一个 SettingsViewController,我想从我的 CurrentViewController 翻转到它,它位于 navigationController 堆栈上。
我尝试执行此操作时遇到各种奇怪的行为,属于 SettingsViewController 的 UIView 将开始动画,滑动到位,navigationButtons 移动,没有任何行为像我想的那样。
-(void)settingsHandler {
SettingViewController *settingsView = [[SettingViewController alloc] init];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view
cache:YES];
[self.navigationController.view addSubview:settingsView.view];
[UIView commitAnimations];
}
以上结果导致视图正确翻转,但是 SettingsViewController 的子视图都位于 (0, 0) 中,并且在转换后,它们“卡入”到位?
是不是因为我在 viewDidLoad 中实例化并添加了我的子视图,就像这样?
- (void)viewDidLoad {
UIImageView *imageBg = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 460.0f)];
[imageBg setImage:[UIImage imageNamed:@"background.png"]];
[self.view addSubview:imageBg];
[imageBg release];
SettingsSubview *switchView = [[SettingsSubview alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 460.0f)];
[self.view addSubview:switchView];
[switchView release];
[super viewDidLoad];
}
1:我应该如何正确地进行“翻转”转换,从 UINavigationController 中的 UIViewController 到新的 UIViewController,然后从新的 UIViewController 再回到驻留在 UINavigationControllers 堆栈上的“原始” UIViewController?
2:在将子视图实例化并添加到 UIViewController 时,我是否应该使用与“viewDidLoad”方法不同的方法?
-问题2更像是“最佳实践”。我已经看到了不同的方法,我在查找或理解生命周期文档以及关于该主题的不同线程和帖子时遇到了麻烦。我错过了“最佳实践”的例子。
非常感谢您提供的任何帮助:)