在iPhone 6,iPhone中处理方向?

时间:2013-02-13 08:54:42

标签: iphone ios ios6

iOS 6中需要哪些方法来处理方向?我用过的是吼叫,这够了吗?

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations

    if (UIInterfaceOrientationLandscapeLeft == interfaceOrientation || UIInterfaceOrientationLandscapeRight == interfaceOrientation) {
    return YES;
    } else {
        return NO;
    }
}

我想让应用程序在iOS5和iOS6中都能正常工作

5 个答案:

答案 0 :(得分:0)

在上述所有步骤之前,请在Targets->Summary ...

中设置支持的方向

enter image description here

答案 1 :(得分:0)

我只知道iOS5 ......一个小修改

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

   return (UIInterfaceOrientationIsLandscape(interfaceOrientation));

} 

答案 2 :(得分:0)

是的,这三个就足够了。也适用于ios6,将preferredInterfaceOrientationForPresentation添加为

  

return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight)

以优先方向启动应用的方法。

答案 3 :(得分:0)

适用于iOS6

//Support all orientation
- (NSUInteger)application:(UIApplication*)application
    supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAll;
}

现在您需要更改根视图控制器

// iOS6 support
// ---
- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}

在iOS6中已弃用,iOS5支持仍然需要。

// ---
- (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

答案 4 :(得分:0)

您只需在.m文件

中添加以下行
#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )

然后您必须在.m文件

中添加以下方法
#ifdef IOS_OLDER_THAN_6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
   return (UIInterfaceOrientationIsLandscape(toInterfaceOrientation));
}
#endif

#ifdef IOS_NEWER_OR_EQUAL_TO_6

- (NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskLandscape;
}
#endif