如何使用 UINavigationcontroller 仅将一个 ViewController 更改为横向模式 [英] How to change only one ViewController to landscape mode with UINavigationcontroller

查看:26
本文介绍了如何使用 UINavigationcontroller 仅将一个 ViewController 更改为横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图控制器,我在 FirstViewController 中有一些视频,如果我单击视频,它将以横向模式显示在 SecondViewController 上,再次单击后退按钮后,FirstViewController 应以 Potrait 模式显示.这是我的代码

I have two view controllers,I have some videos in FirstViewController,if I click on video it will display on SecondViewController with landscape mode,after clicking back button again the FirstViewController should appear in Potrait mode.Here is my code

-(NSUInteger)supportedInterfaceOrientations
 {

     return UIInterfaceOrientationMaskLandscape;
 }

但它对我不起作用.

谢谢

推荐答案

几周前我针对这个问题做了一个简单的解决方法.如果需要,您可以将 rootviewcontroller shouldAutoRotate/supportedInterfaceOrientation 的返回值链接到执行此操作的第二个视图控制器的呈现

I made a simple workaround at this question a few weeks ago. If you want, you can link the return value of the rootviewcontroller shouldAutoRotate/supportedInterfaceOrientation to the presentation of the second view controller doing this

根视图控制器

@property (nonatomic, retain) BOOL autoRotate;
@property (nonatomic, retain) UIInterfaceOrientation interfaceOrientation;

-(void)setAutorate:(BOOL)newValue
{
    _autoRotate = newValue;
}
-(void)setInterfaceOrientation: (UIInterfaceOrientation)newInterface
{
    _interfaceOrientation = newInterface;
}

-(BOOL)shouldAutorotate
{
    return _autoRotate;
}
-(UIInterfaceOrientation)supportedInterfaceOrientation
{
    return _interfaceOrientation;
}

并且在 secondView 控制器中,您必须调用 viewDidAppear 中的 setter 方法来修改值.然后,在 viewDidDisappear 中,或者当您关闭控制器时,您将重置这些值.

And in the secondView controller you have to call the setter method in the viewDidAppear to modify values. Then, in the viewDidDisappear, or when you dismiss the controller, you will reset the values.

这篇关于如何使用 UINavigationcontroller 仅将一个 ViewController 更改为横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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