2013-02-25 34 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