Iphone 我只想在ios(ios 5和ios 6)中进行横向应用
我已经使用了Xcode 4.5.1并使用了这个条件Iphone 我只想在ios(ios 5和ios 6)中进行横向应用,iphone,landscape,uiinterfaceorientation,Iphone,Landscape,Uiinterfaceorientation,我已经使用了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_T
#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
#定义早于_6的IOS([[[UIDevice currentDevice]systemVersion]floatValue]<6.0)
#将IOS_更新的_或等于_定义为_6([[[UIDevice currentDevice]systemVersion]floatValue]>=6.0)
#ifdef IOS_早于_6
-(布尔)应将自动旋转指针面方向:(UIInterfaceOrientation)转换为接口方向{
[image_signature setImage:[self resizeImage:image_signature.image];
返回(toInterfaceOrientation==UIInterfaceOrientationAndscapeLeft);
}
#恩迪夫
#如果定义IOS较新或等于6
-(BOOL)应该自动旋转{
返回YES;
}
-(整数)支持的接口方向{
[image_signature setImage:[self resizeImage:image_signature.image];
返回UIInterfaceOrientationMaskLandscapeLeft;
}
#恩迪夫
我已经在info.plist中添加了密钥。
UI支持接口方向
UIInterfaceOrientationAndscapeRight
UIInterface方向和左视图
并设置支架接口方向
如果我已经在info.plist中添加了密钥并设置了支持方向,并且没有使用下面的代码,那么这个应用程序在ios 5.0中无法工作
这个代码是工作,但我想使用小的替代概念…请帮助我
提前谢谢 还有另一种方法-不设置允许的方向: 尝试此解决方案-它适用于iOS 5和iOS 6 然后,您可以实现shouldRotate。。委托方法,以允许它仅在横向方向之间旋转
祝你好运 你的方法不健康。只有当#ifdef语句为true时,才会编译预处理器块。您所做的是使预处理器语句依赖于运行时参数 您可以尝试删除所有预处理器块。将部署目标定为5.0
编辑:仅供参考,这些方法是回调方法,因此如果需要,系统将调用它们。iOS5将调用shouldAutorotateToInterfaceOrientation方法,同样,iOS6将相应地调用supportedInterfaceOrientations和iOS6的旋转方法。所以,您应该在运行时处理所有系统差异,而不是在编译时,除非您有意为两个不同的系统编译两个不同版本的应用程序 谢谢basar先生……我解决了我的问题……我解释了如何解决我的问题 如果在IOS 5和IOS 6中设置应用程序的方向 然后跟着台阶走 1) 转到项目->选择支持界面方向 示例:-您要选择左横向和右横向。。看到图片了吗 2) 选择方向后,将自动在info.plist(签入info.plist)中添加关键点。如果没有添加,则将在info.plist中添加关键点 例如:-
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
//对于IOS 6
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
[image_signature setImage:[self resizeImage:image_signature.image]];
return UIInterfaceOrientationMaskLandscapeLeft;
}
注:-
1) 不需要条件(IOS版本)…因为这两个都应该自动旋转指向接口方向(IOS 5
)支持的接口方向(IOS 6)
都是委托的,它是调用运行时…(请参阅basar答案)。
2) 如果您只使用IOS 6,则不需要代码。仅使用步骤1和步骤2删除这些预处理器块并添加 为了在ios5和ios6中支持自动旋转,我们需要在ios6的情况下提供回调…`[[UIDevice currentDevice]BegingeratingDeviceOrientationNotifications]
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
我们需要打电话
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
对于ios5
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation ==
UIInterfaceOrientationPortraitUpsideDown)); }
您是否尝试在info.plist(目标摘要)中仅设置一个方向?宏的使用完全不正确…粘贴正确的宏您应该定义这两个变量(
应自动旋转指针面方向:
和应自动旋转
+支持的界面方向
)目标操作系统将自动调用支持的操作系统。至于宏,无论宏定义了什么代码,#ifdef
都会被传递,因为IOS_OLDER_比_6
和IOS_NEWER_或_EQUAL_TO_6
都是被定义的。如果我使用singleViewController?这个解决方案应该在主视图控制器中(或第一个出现的控制器中)——只是为了确保它是横向的。。从那时起,如果不允许旋转,这就不再重要了。我已经将部署目标设置为5.0
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
-(BOOL)shouldAutoRotate{
return YES;
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation ==
UIInterfaceOrientationPortraitUpsideDown)); }