支持的方向

时间:2013-05-20 07:25:41

标签: ios objective-c cocoa-touch

我在另一篇文章中看到了这一点。我知道我需要覆盖iOS5的第一个方法和iOS6的以下两个方法。

iOS 5:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

iOS 6

- (BOOL) shouldAutorotate
{
      return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
      return UIInterfaceOrientationMaskLandscapeRight;
}

但是,我确实对如何正确使用它们有一些疑问。

  1. 假设我在我的XCode项目的设置中设置supportedOrientations,我是否必须实现shouldAutoRotate和SupportedInterfaceOrientations?如果我不这样做会怎么样?
  2. 如果我不覆盖shouldAutoRotate,则默认值为YES?
  3. 如果我在shouldAutorotateToInterface中返回NO,我会收到警告“shouldAutorotateToInterfaceOrientation:对于所有界面方向。它应该支持至少一个方向。”这不好吗?它对我的应用有影响吗?
  4. 你什么时候得到崩溃“支持的方向与应用程序没有共同的方向,并且应该是返回YES;”
  5. 如果我在shouldAutorotate中返回NO并且我有多个supprotedInterfaceOrientations会发生什么?是否与使用肖像相同,因为我的VC不会旋转?
  6. 如果我在shouldAutorotate中返回YES,我的Xcode设置中有多个支持的方向但是我覆盖了supportedInterfaceOrientations但只返回1?

1 个答案:

答案 0 :(得分:2)

我正在通过内存完成这些答案的绝大部分,因此可能会出现一些错误......

  1. 您输入的值将用于所有视图控制器。 如果要指定其他内容,则必须覆盖它们 一个视图控制器中的行为。
  2. 是。在一个新项目中测试它:

    // Should autorotate not implemented
    -(void)viewDidLoad {
         [super viewDidLoad];
         NSLog(@"%@", [self shouldAutorotate]?@"y":@"n");
    }
    
  3. 您收到警告是因为您说不应该自动旋转,而是使用shouldAutorotateToInterfaceOrientation:为他提供多个支持的界面方向。支持方向并给出可能的方向或不提供方向。
  4. 如果您告诉您的应用程序(在.xcodeproj中)支持,例如,仅支持纵向,并在视图控制器中指定您支持的界面方向不包括纵向。
  5. 您告诉系统不要自动旋转。您应该手动进行旋转。状态栏可能会旋转但您的界面不会旋转。
  6. 该屏幕始终处于该界面方向,不会旋转。您在xcodeproj中指定的接口是应用程序可以支持的接口。然后,您可以使用仅支持其中一个或多个方向的特定视图控制器。
  7. 也就是说,通常很难获得确切的预期行为。所以通常的做法是'试用&错误'。或者正如我的老师之一总是说'错误&试用'因为你已经用这种方法犯了错误=)