我有两个视图:一个只有一个按钮(视图1),另一个包含带有搜索栏的tableview(screen2)。当用户在视图1中单击该按钮时,我希望视图1翻转并显示屏幕2.
View 2位于导航控制器内部,导航栏位于顶部。
以下是我现在所拥有的。过渡动画工作并翻转到第二个屏幕,但视图2缺少来自NavigationBar的SearchBar和标题。两者都设置在视图2中。
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
navigationController = [[UINavigationController alloc] init];
bestbuyProducts = [[BestBuyProductsViewController alloc] initWithNibName:@"BestBuyProductsViewController" bundle:nil];
[navigationController pushViewController:bestbuyProducts animated:NO];
[navigationController.view setFrame: [self.view bounds]];
[bestbuyProducts release];
[self.view addSubview:navigationController.view];
[UIView commitAnimations];
谢谢
答案 0 :(得分:4)
启动UINavigationController未正确初始化。使用initWithRootViewController:方法:
bestbuyProducts = [[BestBuyProductsViewController alloc] initWithNibName:@"BestBuyProductsViewController" bundle:nil];
// Initialise the navigation view with the bestbuyProducts view controller
navigationController = [[UINavigationController alloc] initWithRootViewController:bestbuyProducts ];
然后尝试使用模态视图过渡来制作翻转动画,开始更简单,更安全:
[navigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[bestbuyProducts release];
答案 1 :(得分:1)
好的,这是正确的版本
navigationController = [[UINavigationController alloc] initWithRootViewController:bestbuyProducts];
[bestbuyProducts setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navigationController animated:YES];