2013-07-22 48 views
0

我的應用應該以橫向模式啓動。 我想改變手機的方向。 如何手動執行此操作。我試過這樣做不起作用。如何手動更改方向

shouldAutorotateToInterfaceOrientation: 

是否有其他方法?

回答

0

在項目設置中,您可以設置您的應用允許的方向。將其設置爲LandscapeLeft和LandscapeRight。這會阻止您的應用進入Potrait模式,無論您的應用啓動之前設備的方向如何。

手動強制改變方向

在iOS中,你不能直接手動設置設備的方向。但是,您可以使用此方法完成您的工作。

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO]; 

通常的方式

或者,您也可以轉到您的實現文件,你可以指定該方法允許的方向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
//Return YES if you want to allow all orientations 
return UIInterfaceOrientationLandscapeRight; //if you want to allow landscape right &c 
}