1

我开发了一个通用应用程序,我想支持 IPAD 的所有方向,但对于 Iphone,我只想要 UIInterfaceOrientationPortrait 和 UIInterfaceOrientationPortraitUpsideDown 只为此我有

-(BOOL)shouldAutorotate {
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
        return NO;
    }else{
        return YES;
    }
}
- (NSUInteger)supportedInterfaceOrientations{

     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
         return UIInterfaceOrientationMaskPortrait;
     }else{
        return UIInterfaceOrientationMaskAll;
     }

} 
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){

    return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ;
     }else{
         return YES;
     }

}

但仍然没有停止横向的定位

4

2 回答 2

6

只需从摘要中禁用除iPhoneUIInterfaceOrientationPortrait的和之外UIInterfaceOrientationPortraitUpsideDown的所有其他方向,如下面的描述。在图片中,颠倒被禁用,请启用它。谢谢。

在此处输入图像描述

于 2013-07-02T08:56:40.510 回答
1

对于倒置的肖像,您必须使用导航控制器

1)我创建了一个新的UINavigationController子类,并添加了shouldAutorotate和supportedInterfaceOrientation方法:

     // MyNavigationController.h:
     #import <UIKit/UIKit.h>

     @interface MyNavigationController : UINavigationController

     @end

    // MyNavigationController.m:
     #import "MyNavigationController.h"
     @implementation MyNavigationController
     ...
    - (BOOL)shouldAutorotate {
    return YES;
     }

     - (NSUInteger)supportedInterfaceOrientations {
     return UIInterfaceOrientationMaskAll;
     }
    ...
       @end

2)在 AppDelegate 中,我确实使用了我的新子类来显示我的根 ViewController(它是 introScreenViewController,一个 UIViewController 子类)并且确实设置了 self.window.rootViewController,所以看起来:

      nvc = [[MyNavigationController alloc]              initWithRootViewController:introScreenViewController];
     nvc.navigationBarHidden = YES;
      self.window.rootViewController = nvc;
      [window addSubview:nvc.view];
   [window makeKeyAndVisible];
于 2013-07-02T09:14:41.500 回答