在uinavigation控制器中转换为横向旋转 [英] Transitioning to landscape rotation within a uinavigationcontroller

查看:83
本文介绍了在uinavigation控制器中转换为横向旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从uinaviagtion控制器中推送一个横向视图,其初始视图是在纵向...
所以你单击一个按钮或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).

现在,唯一的问题是,模态视图中的导航界面没有后退按钮,如果我们正在查看其根视图。这打破了错觉(并使得用户很难回来)。解决方案是一个诀窍:将景观视图两次推入导航界面,然后将其显示为模态视图。这样,在导航界面中显示的是堆栈上的第二视图,因此有一个后退按钮。然后,在导航控制器委托中,当用户尝试返回到您所知的根级别时,捕获后退按钮并关闭模态视图。所以:

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];
}

这篇关于在uinavigation控制器中转换为横向旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆