2010-03-05 19 views

回答

4

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientation]是一個私有API,你可以發現簽名是隻讀的(見here)。

如果你想設置的設備方向爲縱向或其他方式,你應該覆蓋shouldAutorotateToInterfaceOrientation:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation == UIDeviceOrientationPortrait); 
} 
+2

的UIDevice是不是私人的API。 – thierryb 2010-03-05 13:23:22

+0

對不起,這是一個錯誤,我只是告訴setOrientation是私人的。 – 2010-03-05 13:36:04

0

您可以在您的應用程序的plist

1

Yes you'll get rejected添加UIInterfaceOrientation。

您可以更改框架並將變換應用到關鍵窗口,並更改狀態欄方向(這是公開的)以模擬更改方向。

0

你可以試試這段代碼。它完美對我的應用程序

UIApplication* application = [UIApplication sharedApplication]; 
if (application.statusBarOrientation != UIInterfaceOrientationPortrait) 
{ 
    AppDelegate* app = [[UIApplication sharedApplication] delegate]; 
    UIViewController *c = [[UIViewController alloc]init]; 
    [app.viewController presentModalViewController:c animated:NO]; 
    [app.viewController dismissModalViewControllerAnimated:NO]; 
    [c release]; 
} 

其中app.viewController是應用程序的RootViewController的