iOS 6的supportedInterfaceOrientations问题(iOS 6 suppo

2019-07-05 11:01发布

In my view controller, I implement two methods for controlling interface orientation:

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

In the supportedInterfaceOrientations method, I return UIInterfaceOrientationMaskPortrait but at that time I realized that the shouldAutorotate method is not being called.

But I change to return UIInterfaceOrientationPortrait in the supportedInterfaceOrientations method. The shouldAutorotate method is being called, but there is an error that mentions in following:

UIApplicationInvalidInterfaceOrientation, reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

By the way, I select all orientations in the supported interface orientations.

EDITED

i use viewController and embed with navigationController. here is AppDelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate,UINavigationControllerDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (readonly, strong, nonatomic) UINavigationController *navController;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
@end

in didFinishLaunchingWithOptions method under AppDelegate.m

      navController = (UINavigationController *)self.window.rootViewController;
                IPad_HomeViewController *rootVC=(IPad_HomeViewController *)navController.topViewController;
                rootVC.managedObjectContext = self.managedObjectContext;
return YES;

in my IPad_HomeViewController,

@interface IPad_HomeViewController : UIViewController <UINavigationControllerDelegate>
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@end

Answer 1:

- (BOOL) shouldAutorotate {
    return YES;
}

// for landscape
- (NSInteger) supportedInterfaceOrientations {
    return (1 << UIInterfaceOrientationLandscapeLeft) | 
           (1 << UIInterfaceOrientationLandscapeRight);
}

如上所述,检查出的屏蔽值的具体方位:UIInterfaceOrientationMask值。 UIInterfaceOrientationMask



Answer 2:

两点:

  1. 您的错误信息,使完整的意义,因为它是没有意义的使用UIInterfaceOrientationPortrait从返回值supportedInterfaceOrientations ,它返回一个位掩码。 使用的一个UIInterfaceOrientationMask值。

  2. 你似乎是担心,如果你使用正确的UIInterfaceOrientationMaskPortrait ,即iOS不显示来电shouldAutorotate 。 它可能只调用shouldAutorotate如果审议了物理设备的物理方向和对应用程序的当前方位supportedInterfaceOrientations ,可能需要旋转。 为什么要检查shouldAutorotate ,如果它的结论是,该设备是在已可接受的方向是什么?

见supportedInterfaceOrientations和处理视图旋转以获取更多信息。



Answer 3:

我知道这听起来很基本的,但我是令人头大我的大脑找出方向的问题,而在我的iPhone测试 - 我在人像模式中的物理自动锁定模式 - 因此没有我改变编程要紧 - 认为这应该故障排除步数1 !



Answer 4:

为了改变方向设置,选择菜单Targets->摘要 - >支持的设备取向和变化如下。

如果方向按钮是黑的时候,这意味着你选择了它作为方向之一。



Answer 5:

而不是使用整数你为什么不使用一个布尔值,并插入if语句在那里检测到任何你想要的方向申报方向。 这里是一个示例代码,我希望能帮助你:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
    return YES;
}
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
    return YES;
}
return NO;
}

您可以添加所有方向的if语句,它应该只是罚款。 阿德里安

编辑:

如果你想为iOS 6的一个选项,下面的代码应该只是罚款你。

- (BOOL) shouldAutorotate
{
return YES;
 }

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft   | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}

你可以改变几乎所有与此支撑取向在IOS 6编码快乐

编辑1:

旋转只有某些viewcontrollers以一定的方式,只需要使用iOS 6的代码,我在所有上面贴viewcontrollers 。 这里的步骤:

  1. 在所有四个项目的水平internfaceorientations的位置,去ahean并把一切都关掉这样的应用程序会去默认。

  2. 实现,我在所有提供的IOS 6代码viewcontrollers

  3. 而非是宣称没有在shouldautorotate方法。
  4. 在第二种方法中,插上你想要的任何方式的定向。

这应该为你做的伎俩。 快乐编码



文章来源: iOS 6 supportedInterfaceOrientations issue