我有一个用户导航的UINavigationController。 将特定UIViewController推入导航堆栈时,navigationBar中会出现一个“settings”按钮。当用户单击此按钮时,我想将当前的视图/控制器(即屏幕上的所有内容,包括navigationBar)翻转到设置视图。由属于UINavigationController的UIViewController完成的UIViewAnimation?
所以我有一个SettingsViewController,我想从我的CurrentViewController中翻到导航控制器堆栈上。
我得到各种奇怪的行为,试图做到这一点,属于SettingsViewController的UIViews将开始动画,滑动到位,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:我应该如何正确地做了“翻转”过渡,从UIViewController中的UINavigationController的范围内,一个新的UIViewController,然后从新的UIViewController,并回到“原始”的UIViewController驻留在UINavigationControllers堆栈?
2:在实例化和添加子视图到UIViewController时,我应该使用不同的方法,比“viewDidLoad”方法吗?
-question 2更像是一个“最佳实践”的东西。我看到了不同的方式 这样做,我无法找到或理解生命周期文档和主题上的不同主题和帖子。我错过了“最佳实践”的例子。
非常感谢你的。如果你想以编程方式创建视图层次,做到这一点是-loadView的地方给予:)
谢谢cduhn。 这是一个很好的解释和完美的例子。 – RickiG 2010-04-11 19:30:58