2010-06-18 75 views
0

我正在處理由TabBar控制器組成的應用程序。 在它的選項卡中,我有一個UITableViewController的子類,在這個列表中,我在第一個單元格中有一個Core-plot圖形,在下面的4個單元格中有一些其他數據。 當我在shouldAutorotateToInterfaceOrientation方法中返回YES時,我期望列表視圖的自動調整發生,但是......什麼也不做。 當我在willRotateToInterfaceOrientation方法中添加一些日誌時,它們不會顯示。 有什麼我錯過了嗎? 非常感謝, 呂克iphone無法在TabBar控制器中旋轉視圖

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations 
//return (interfaceOrientation == UIInterfaceOrientationPortrait); 
NSLog(@"Orientation"); 
return YES; 
} 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

NSLog(@"Rotating"); 

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
    NSLog(@"view land:%@", self.view); 
} 

if (toInterfaceOrientation == UIInterfaceOrientationPortrait) 
{ 
    NSLog(@"view portrait:%@", self.view); 
} 
} 

回答

2

是,除非你繼承UITabBarController和正確地覆蓋其shouldAutorotateToInterfaceOrientation:方法將無法正常工作。

參見my question here and related answers

+0

非常感謝Luc – Luc 2010-06-19 21:05:02

0
add this method in category 
@implementation UITabBarController(UITabBarControllerCategory) 

-(BOOL)shouldAutorotateToInterfaceOrientation: 
(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate]; 

    if ([AppDelegate isLandScapeOnly]){ 
    return NO; 
} 
return YES; 
}