我想从 uinaviagtioncontroller 中推送一个横向视图,它的初始视图是纵向的...因此,您单击一个按钮或 tableviewcell,屏幕旋转 90° 进入新视图..
I want to push a landscape view from within a uinaviagtioncontroller, whose initial view is in portrait... So you click a button, or tableviewcell, and the screen rotates 90° into the new view..
我将如何管理它?这类似于 Youtube 应用在从电影信息屏幕转换到实际电影时的工作方式.
How would I manage that? This is similar to how the Youtube app works when transitioning from movie info screen to the actual movie.
(注意:我对用户拿着设备的旋转方向不感兴趣)
(note: i am not interested in what rotation the user is holding the device)
当从电影信息屏幕转换到实际电影时,YouTube 应用程序中出现的不是导航界面 - 它是一个模态视图.这总是可靠的:如果您以模态方式显示视图(使用 presentModalViewController
)并且它只能出现在一个方向上,则应用会旋转到该方向.
What appears in YouTube app when transitioning from the movie info screen to the actual movie is not navigation interface - it's a modal view. This always works reliably: if you show a view modally (using presentModalViewController
) and it can appear in only one orientation, the app rotates to that orientation.
因此,解决方案是,不要将横向视图推送到导航控制器中;将其呈现为模态视图.
So, the solution is, don't push your landscape view into the navigation controller; present it as a modal view.
好的,但也许您想欺骗用户相信我们仍在导航界面中?然后给模态视图一个导航界面,配置成看起来像主导航界面!因此,当您呈现模态视图时,它会向用户显示,就好像导航界面已经旋转(尽管不会有旋转动画).
Okay, but perhaps you want to fool the user into believing that we are still in the navigation interface? Then give the modal view a navigation interface configured to look like the main navigation interface! So when you present the modal view, it will appear to the user as if the navigation interface has rotated (though there will not be a rotation animation).
现在,唯一的问题是,如果我们查看它的根视图,模式视图中的导航界面没有返回按钮.这打破了这种错觉(并使用户很难回来).解决方案是一个技巧:将横向视图 两次 推送到导航界面,然后将其呈现为模态视图.这样,导航界面中显示的是堆栈上的 second 视图,因此有一个返回按钮.然后,在导航控制器委托中,当用户尝试返回到您所知道的根级别时,抓住后退按钮并关闭模式视图.所以:
Now, the only problem is that the navigation interface in the modal view has no Back button if we are looking at its root view. This breaks the illusion (and makes it hard for the user to come back). The solution to that is a trick: push the landscape view twice into the navigation interface before presenting it as a modal view. That way, what is showing in the navigation interface is the second view on the stack, and so there is a Back button. Then, in the navigation controller delegate, catch the Back button and dismiss the modal view when the user tries to return to what you know to be the root level. So:
- (void) doButton: (id) sender { // appear to navigate into a landscape view
SecondViewController* sec = [[SecondViewController alloc] init];
sec.title = self.title; // to give the correct Back button title
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:sec];
SecondViewController* sec2 = [[SecondViewController alloc] init];
[nav pushViewController:sec2 animated:NO];
[self presentModalViewController:nav animated:YES];
nav.delegate = self; // so that we know when the user navigates back
}
// and here's the delegate method
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if (viewController == [navigationController.viewControllers objectAtIndex:0])
[self dismissModalViewControllerAnimated:YES];
}
这篇关于在 uinavigationcontroller 中转换为横向旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!