简体   繁体   English

设备方向纵向仅适用于一个视图控制器

[英]Device orientation portrait only for one view controller

I want only portrait orientation only in one view controller. 我只希望在一个视图控制器中纵向放置。 I am doing this : 我正在这样做:

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window{

    //    UIInterfaceOrientationMaskLandscape;
    //    24
    //
    //    UIInterfaceOrientationMaskLandscapeLeft;
    //    16
    //
    //    UIInterfaceOrientationMaskLandscapeRight;
    //    8
    //
    //    UIInterfaceOrientationMaskPortrait;
    //    2


    //    return UIInterfaceOrientationMaskLandscape;
    return 2;
}  

No success !! 没有成功!
I have tried many permutations and combinations as suggested on google but still not working. 我已经尝试过许多建议在Google上进行的排列组合,但仍然无法正常工作。

您应该在shouldAutorotate返回YES,因为如果您的应用是横向的,在其他情况下您的视图将不会旋转回纵向。

You should try returning YES for shouldAutoRotate to make the below supportedInterfaceOrientations to become effect and also there is no method called -(NSInteger)supportedInterfaceOrientations:(UIWindow *)window on UIViewController instead use: 您应该尝试为shouldAutoRotate返回YES,以使下面的supportedInterfaceOrientations生效,并且在UIViewController上没有名为-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window的方法,而是使用:

This code must go in your view controller which you want to be in portrait only. 此代码必须放在您希望仅以纵向显示的视图控制器中。

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskPortrait;
}

I'm linking you a post where I answered a question like this. 我正在将您链接到一个帖子,其中我回答了这样的问题。 I hope it will bel helpful 希望对您有所帮助

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果应用程序设备的方向是纵向的,那么如何仅在iOS中为一个视图构建者设置强制横向,Swift 2.3 - if app device orientation is portrait how to set force landscape only for one view constroller in ios, swift 2.3 仅针对一个视图控制器从静态库维护iOS纵向方向 - Maintaining iOS portrait orientation from a static library for one view controller only 仅支持纵向应用程序中视频播放器视图控制器的所有方向 - Support all orientation only for video player view controller in a portrait application 只有一个视图控制器响应方向设置 - Only One View Controller Responds To Orientation Settings 将视图控制器强制为仅纵向 - Force view controller to portrait only 为一个视图控制器启用纵向和横向,为swift中的其他视图控制器启用纵向? - Enable portrait and landscape for one view controller and only portrait for other view controllers in swift? 对于一个视图,将力方向设置为“纵向”,对于另一个视图,将力和方向设置为“纵向” - Force orientation to be Portrait for one view and both for another MPMoviePlayerController全屏旋转,而父视图控制器仅支持纵向方向 - MPMoviePlayerController rotating in full screen while the parent View Controller only supports portrait orientation iPhone iOS 6 UITabBarController仅限于纵向,如何使Modal View Controller支持横向方向 - iPhone iOS 6 UITabBarController Portrait Only, How to have Modal View Controller support Landscape Orientation 方向纵向和PortraitUpSideDown仅适用于一个窗口 - Orientation Portrait and PortraitUpSideDown Only For One Window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM