2013-02-25 32 views
1

我创建了一个应用程序在Xcode 4.5使用自动布局启用。由于它与iOS 5不兼容(在测试之前不知道),我没有从故事板中选中自动布局。现在,在模拟器中测试时,视图的内容全部顺时针旋转。Xcode Autolayout - 查看旋转时未选中

该应用程序最初是在横向(在Xcode看起来很好)。模拟器将在横向上启动,但视图内的所有内容看起来像在取消选中自动布局后已经旋转。

实施例:enter image description here

我试图用新的视图控制器和它仍显示像上面。初始方向已设置为横向。任何解决方案

回答

2

对于解决方向问题,请做到这一点。

在.PCH文件

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

定义这些宏并编写viewContrller.m这里面方法

#ifdef IOS_OLDER_THAN_6 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
    (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 
#endif 

#ifdef IOS_NEWER_OR_EQUAL_TO_6 
-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 
- (NSUInteger)supportedInterfaceOrientations 
{ 
    return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight); 
} 
#endif 
+0

完美,感谢你及时的答复! – NoMachine 2013-02-25 04:45:48

+0

请注意,预编译指令(#define,#ifdef)在*编译时扩展*,而不是* runtime *。这两个宏都是在编译源代码时定义的,因此这三个方法都将被编译为可执行文件。 – 2013-02-25 06:55:48

0

还有一件事,当UINavigationController参与,子类UINavigationControlleroverriding supportedInterfaceOrientations。现在

#import "UINavigationController+Orientation.h" 

@implementation UINavigationController (Orientation) 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

@end 

,iOS的容器(如UINavigationController的)不咨询自己的孩子,以确定他们是否应该自动旋转。
如何子类
1.添加一个新的文件(下可可触摸目的的C类)
2. Category:定向Category On:UINavigationController的
3.上面的代码添加到UINavigationController+Orientation.m