4

我已经使用了 Xcode 4.5.1 并使用了这个条件

#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )
#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )


#ifdef IOS_OLDER_THAN_6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    [image_signature setImage:[self resizeImage:image_signature.image]];
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
#endif
#ifdef IOS_NEWER_OR_EQUAL_TO_6
-(BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    [image_signature setImage:[self resizeImage:image_signature.image]];
    return UIInterfaceOrientationMaskLandscapeLeft;
}
#endif

我已经在 info.plist 中添加了密钥。 在此处输入图像描述

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
    </array>

并设置支持界面方向

如果我在 info.plist 中添加了密钥并设置了支持方向并且不使用以下代码,则应用程序在 ios 5.0 中不起作用

此代码有效,但我想使用小的替代概念..请帮助我..

提前致谢!!

4

4 回答 4

3

你的方法不健康。只有当#ifdef 语句为真时,预处理器块才会被编译。您所做的是使预处理器语句依赖于运行时参数。

您可以尝试删除所有预处理器块。将您的部署目标设为 5.0。

编辑:仅供参考,这些方法是回调方法,因此如果需要,它们将被系统调用。iOS5 会调用 shouldAutorotateToInterfaceOrientation 方法,同样 iOS6 会调用supportedInterfaceOrientations 和iOS6 的rotation 方法。因此,您应该在运行时而不是编译时处理所有系统差异,除非您故意为两个不同的系统编译两个不同版本的应用程序。

于 2012-10-17T12:20:20.337 回答
1

谢谢先生。basar...我解决了我的问题...我解释了如何解决我的问题...

如果您在 IOS 5 和 IOs 6 中的应用程序中设置方向

然后按照步骤

1)转到项目 - >选择支持界面方向

示例:-您要选择横向左和横向右.. 看图片 在此处输入图像描述

2)当您选择方向时,然后自动在 info.plist 中添加密钥(检查 info.plist )如果没有添加,那么您在 info.plist 中添加密钥

例子:-

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
    </array>

3)在每个viewcontroller中添加代码

// 对于IOS 5

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
        [image_signature setImage:[self resizeImage:image_signature.image]];
        return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }

// 对于IOS 6

-(BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    [image_signature setImage:[self resizeImage:image_signature.image]];
    return UIInterfaceOrientationMaskLandscapeLeft;
}

笔记:-

1)不需要条件(IOS版本)......因为两者shouldAutorotateToInterfaceOrientation (IOs 5supportedInterfaceOrientations (IOS 6)都是委托并且它是调用运行时...... (见basar答案)。

2)如果你只工作 IOS 6 那么不需要代码。仅适用于第 1 步和第 2 步

于 2012-10-19T07:26:47.177 回答
0

还有另一种方法 - 没有设置允许的方向:

试试这个解决方案 - 它适用于 iOS 5 和 iOS 6。

UINavigationController 强制旋转

然后,您可以实现 shouldRotate .. 委托方法,以允许它仅在横向之间旋转。

祝你好运!

于 2012-10-17T12:19:13.003 回答
-2

删除那些预处理器块并添加它以支持 ios5 和 ios6 中的自动旋转,我们需要在 ios6 的情况下提供回调......`[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

我们需要打电话

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;

}

-(BOOL)shouldAutoRotate{
    return YES;
  }

适用于 iOS5

  (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
        {
            return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation ==
        UIInterfaceOrientationPortraitUpsideDown)); }
于 2013-08-22T07:34:10.907 回答