2013-08-28 36 views
0

我的項目有很多視圖控制器(.xib文件)。 我想要:視圖控制器只能有縱向。但其他視圖控制器只能具有橫向方向。或者視圖控制器可以具有縱向和橫向兩種方向。 現在我想要一個視圖控制器只有橫向(沒有縱向)。請幫幫我。謝謝。如何在iOS中只設置視圖控制器的縱向?

+0

檢查這一項([iOS中6.0接口方向] http://stackoverflow.com/questions/12404556/interface-定位功能於IOS-6-0)。嘗試此操作後讓我知道您的回覆。 –

+0

謝謝。我會嘗試! :) – user2678221

+0

通過http://stackoverflow.com/questions/37085341/how-to-set-certain-view-controller-to-be-landscape-and-portrait-and-certain-to-b/37086217#37086217 –

回答

0
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation); 
} 

更新:

您可以通過創建UINaviagationController

爲.h文件中的代碼的類別做,這是

@interface UINavigationController (autorotation) 

-(BOOL)shouldAutorotate; 
-(NSUInteger)supportedInterfaceOrientations; 

和.m文件代碼

@implementation UINavigationController (autorotation) 

    -(BOOL)shouldAutorotate 
    { 

     UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; 
     [self.topViewController shouldAutorotate]; 
     return YES; 

    } 

    -(NSUInteger)supportedInterfaceOrientations 
    { 
     return UIInterfaceOrientationMaskAll; 

    } 
    @end 
+0

我試過了。但它不起作用:( – user2678221

+0

我的xcode不能解決什麼是topViewController – user2678221

+0

你需要根據你的適合性修改代碼我剛剛給你的概括形式 –

相關問題