自动旋转锁定,以编程方式

Van*_*nya 7 iphone objective-c

有人知道是否有可能只为一个视图以编程方式锁定iPhone的自动旋转?我想在半透明视图中提供一些帮助,但我想只支持横向,即使所有其他视图都可以旋转.因此,当此视图位于顶部时,我希望锁定旋转.

TNX

编辑:更多细节:一个UIController有7个UIView ...我希望在最后一个发生在顶部时锁定自动旋转.

小智 14

这个问题在一年前被问过,但是现在已经在iOS 6中弃用了已接受的方法,所以如果有人有兴趣在iOS 6中这样做,那么你需要在最顶层的控制器上使用supportedInterfaceOrientations.

想象一下,你有这样的设置......

  • 标签栏控制器
    • 导航控制器
      • 查看控制器

...然后,您需要在选项卡栏控制器上设置supportedInterfaceOrientations方法.

创建标签栏控制器(或导航控制器,如果它位于顶部)的子类,并在其中设置这些方法...

- (BOOL)shouldAutorotate {
    //Use this if your root controller is a navigation controller
    return self.visibleViewController.shouldAutorotate;
    //Use this if your root controller is a tab bar controller
    return self.selectedViewController.shouldAutorotate;
}

- (NSUInteger)supportedInterfaceOrientations {
    //Navigation Controller
    return self.visibleViewController.supportedInterfaceOrientations;
    //Tab Bar Controller
    return self.selectedViewController.supportedInterfaceOrientations;
}
Run Code Online (Sandbox Code Playgroud)

...然后在您的个人视图控制器中,您可以设置所需的属性...

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    //return supported orientation masks
    return UIInterfaceOrientationMaskLandscape;
}
Run Code Online (Sandbox Code Playgroud)


Sim*_*Lee 4

使用以下...

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

  • 在 iOS 6.0 中已弃用。而是重写supportedInterfaceOrientations 和preferredInterfaceOrientationForPresentation 方法。) (4认同)