2

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 中工作

4

5 回答 5

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);
}
于 2013-02-13T09:13:39.357 回答
0

在所有步骤之前,在Targets->Summary...中设置支持的方向

在此处输入图像描述

于 2013-02-13T09:00:49.283 回答
0

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

   return (UIInterfaceOrientationIsLandscape(interfaceOrientation));

} 
于 2013-02-13T09:01:57.170 回答
0

是的,这三个就够了。也为 ios6 添加preferredInterfaceOrientationForPresentationwith return as

return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight)

以您喜欢的方向启动应用程序的方法。

于 2013-02-13T09:04:00.307 回答
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
于 2013-02-13T10:10:47.330 回答