2010-06-14 32 views
1

我已經使用此代碼,但它是私人API,蘋果也拒絕!如何使用pushViewController將我的UIViewController更新爲當前方向?

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; 

,如果我在景觀轉動我的設備,然後打開我的應用程序將表現爲人像模式,我需要我的設備旋轉到另一個方向,然後它會更新。

如何在調用UIViewController時將其更新爲正確方向?

回答

0

你應該在你的UIViewController類使用如下代碼:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

如果u需要在運行時更新的方向,然後我只好返回其他不變

return (interfaceOrientation == UIInterfaceOrientationPortrait);

+0

感謝雅科夫,該代碼會在設備改變方向時調用,它可以回答我的問題,也就是當推我的View時它會呈現不正確的方向。所以如果我用setOrientation強制它:它會被蘋果拒絕。 – RAGOpoR 2010-06-14 04:36:09

+0

所以...你也會嘗試添加'Initial interface orientation'屬性到info.plist中。例如:您可以設置值'風景(右側主頁按鈕)'或'肖像(頂部主頁按鈕)'。 – Yakov 2010-06-14 18:01:03

相關問題