2010-09-20 35 views
2

當應用程序處於橫向模式(我打算強制執行)時,顯示模式視圖會導致父視圖旋轉到縱向模式。如果將shouldAutoRotateToInterfaceOrientation的返回值設置爲NO,則父代不會旋轉,但是模式會從側面滑入並側向顯示。下面是揭示模態的代碼。iPad Modal View旋轉parentViewController查看

- (IBAction)loadExistingGame:(id)sender { 

SavedGamesTableViewController *savedGames = [[SavedGamesTableViewController alloc] initWithStyle:UITableViewStyleGrouped]; 
savedGames.modalPresentationStyle = UIModalPresentationFormSheet; 
[self presentModalViewController:savedGames animated:YES]; 

[savedGames release]; 

}

根據要求在這裏是的SavedGamesTableViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Override to allow orientations other than the default portrait orientation. 
return YES; 

}

+0

請出示的'內SavedGamesTableViewController shouldAutoRotateToInterfaceOrientation'實施。 – 2010-09-20 02:17:52

+0

增加了方法,但它只是鍋爐板生成的代碼。 – Kyle 2010-09-20 02:56:05

回答

2

好吧,我想清楚需要做些什麼來解決它。包含可能方位列表的plist文件需要限制爲單個橫向視圖。只有當方向與plist文件中的唯一方向相匹配時,模式表視圖的父級才需要讓shouldAutoRotateToInterfaceOrientation方法返回YES。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Overriden to allow any orientation. 
return interfaceOrientation = UIInterfaceOrientationLandscapeRight; 

}

模態的ViewController應爲相同的方法返回NO。

0

的shouldAutoRotate方法的基於

當應用程序的內容在土地上(,我打算強制), 顯示模態視圖導致 父視圖旋轉到肖像 模式。

根據要求這裏是 的 SavedGamesTableViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Override to allow orientations other than the default portrait orientation. 
return YES; 
} 

的shouldAutoRotate方法的內容,那麼你的意思是,父視圖控制器尚未設置爲僅強制使用橫向方向,並且當您顯示設置爲允許所有方向的模式視圖時,您就是w當您將設備旋轉至肖像時,爲什麼您的父視圖旋轉爲縱向?我不明白你的問題......你是不是說父視圖控制器當前設置爲允許旋轉爲縱向?這不正是應該發生的事情嗎?

+0

沒有設備沒有被旋轉。顯示模態視圖時,模態的父對象會旋轉。 – Kyle 2010-09-20 14:20:25

+0

除了'SavedGamesTableViewController'外,還有另一個控制器在屏幕上顯示嗎?該文檔指出,所有屏幕上的控制器都必須就其發生的自動旋轉達成一致;如果該模式對話框中的屏幕上只有一個視圖控制器設置爲僅使用肖像,則只能以肖像顯示。 – 2010-09-20 16:36:49

+0

屏幕上唯一的其他控制器是模態中包含的tableviewcontroller。它具有與shouldautorotate ...方法相同的樣板代碼。 – Kyle 2010-09-20 17:30:09

0

我在調出模態郵件視圖時遇到類似問題。強制旋轉不適用於我,但在應用程序的主視圖控制器而不是子視圖控制器上調用presentModalViewController可解決此問題。

+0

沒有辦法。我甚至使用window.rootViewController,但仍然沒有改變。 – stigi 2011-05-05 15:09:32

0

我看到了相同的行爲;在我的情況下,問題是我已經實現了shouldAutorotateToInterfaceOrientation無條件爲父視圖控制器返回YES,而不是爲呈現的模式視圖控制器返回。所以我懷疑Shaggy Frog的評論是關鍵:無論你是否想要強制橫向模式,你都需要確保兩個視圖控制器的shouldAutorotateToInterfaceOrientation實現同意或怪異隨後發生。

0
UIViewController *vc = /* create view controller */; 
UINavigationController *nc = nil; 
if (IOS_VERSION_LESS_THAN_6_0) { 
    nc = [[MyCustomNavigationControllerSupportingAllOrientations alloc] initWithRootViewController:vc]; 
} else { 
    nc = [[UINavigationController alloc] initWithRootViewController:vc]; 
} 
[self.navigationController presentModalViewController:nc animated:YES]; 

在iOS6上,我使用UINavigationController。

在預iOS6的我繼承UINavigationController的,就像這樣:

@interface MyCustomNavigationControllerSupportingAllOrientations : UINavigationController 
@end 

@implementation MyCustomNavigationControllerSupportingAllOrientations 
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 
@end