2013-04-04 48 views
0

我有UITableViewController其中一個選項卡上的是UINavigationViewControllerUINavigationController根視圖控制器是UITableViewController,當單擊單元格時,出現UIViewController,必須將其鎖定在Landscape中。在UINavigationController中只處理UIViewController

我希望每個控制器都被鎖定在Portrait中,除了提到的UIViewController必須鎖定在Portrait之外。

我曾嘗試以下:

CustomTabBarController.m:

#import "CustomTabBarController.h" 

@implementation CustomTabBarController 

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // You do not need this method if you are not supporting earlier iOS Versions 
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 

- (BOOL)shouldAutorotate{ 
    return YES; 
} 

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

@end 

CustomNavigationController.h:

#import "CustomNavigationController.h" 

@implementation CustomNavigationController 

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

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

@end 

而在UIViewController中那個畝T爲鎖定在風景,我已經把:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)); 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

但它不工作,我可以將它旋轉到橫向,它就會鎖定在風景,但我希望它在景觀自動出現。

有什麼建議嗎?

回答

0

我以前遇到過一個很大的問題,UITabBarController不尊重我支持的顯示視圖控制器的接口方向。

我通過分類UITabBarController解決了這個問題,並在選擇某個項目時進行捕獲。然後我會自己調用視圖控制器,詢問支持的方向是什麼,如果需要的話可以自己強制旋轉。我也會在旋轉時調用選定的視圖控制器來設置/更改我支持的方向。

我執行UITabBarDelegate並使用didSelectItem來捕獲標籤開關。我不確定現在是否有更好的方法來做到這一點。

0

嘗試重寫方法

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

0

該方法試圖阻止一些定向爲特定窗口:

– application:supportedInterfaceOrientationsForWindow: 
相關問題