【问题标题】:How to set only portrait orientation for view controller in iOS?如何在 iOS 中只为视图控制器设置纵向?
【发布时间】:2013-08-31 07:58:08
【问题描述】:

我的项目有很多视图控制器(.xib 文件)。 我想要:视图控制器只能有纵向。但是,其他视图控制器只能具有横向方向。或者视图控制器可以同时具有纵向和横向。 现在我想要一个视图控制器只有横向(没有纵向)。请帮我。谢谢你。

【问题讨论】:

标签: iphone xcode ios6 view landscape


【解决方案1】:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}

更新:

你可以通过创建 UINaviagationController 的类别来做到这一点

.h 文件的代码是

@interface UINavigationController (autorotation)

-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;

.m 文件的代码是

 @implementation UINavigationController (autorotation)

    -(BOOL)shouldAutorotate
    {

        UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
        [self.topViewController shouldAutorotate];
        return YES;

    }

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;

    }
    @end

【讨论】:

  • 您需要根据自己的适用性修改代码。我刚刚给了你一个概括的形式。
  • 我尝试为 UIView 设置。我正在使用 iOS 6
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-02
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
  • 2013-05-18
相关资源
最近更新 更多