2010-10-25 42 views
0

的UIViewController A,B。UIInterfaceOrientation Problemer

一個實現橫屏,一轉B. 怎麼辦呢?取消橫屏爲B.

B碼:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

// Return YES for supported orientations 
return NO; 
} 

也不行!爲什麼?? 請幫幫我!謝謝!

+0

你是否在所有情況下返回NO?你的觀點應該至少支持1個方向。 – skorulis 2010-10-25 02:10:52

回答

0

如果B位於帶A的標籤欄上,這將不起作用。您需要以模態方式呈現B或將其推送到導航控制器上 - 並且還需要爲B中的至少一個方向返回YES。

標籤欄控制器僅支持所有視圖支持的方向。

+0

[self.navigationController pushViewController:B animated:YES];做這個A轉向B!怎麼辦? – raien 2010-10-25 03:52:52

+0

據我所知,這是不可能的。 – 2010-10-26 01:35:53

0

我剛剛在iOS 5.1下的應用程序中修復了這個問題。這是一個古老的問題,但我在這裏留下了後代,因爲我沒有看到任何人解決這個問題,但沒有應用CGAffineTransform代碼的gobs,也沒有解決真正的問題,即UIInterfaceOrientation和UIDeviceOrientation不同步。

在我的情況下,我只需要修正方向,當我從僅肖像的ViewController進入方向時,當設備在轉換之前被物理旋轉時進入縱向和橫向ViewController。

// The "Interface Orientation" and the "Device Orientation" can become separated in some cases. 
// Make sure the view controller only supports the interface orientation for the current device rotation. 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    int deviceRotation = [[UIDevice currentDevice] orientation]; 
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 

    if (deviceRotation == UIDeviceOrientationUnknown || 
     deviceRotation == UIDeviceOrientationFaceUp || 
     deviceRotation == UIDeviceOrientationFaceDown) 
     return YES; 

    if (deviceRotation != interfaceOrientation) 
     return NO; 
    else 
     return YES; 
} 
相關問題