2012-06-14 44 views
0

我想強制我的視圖去風景,只是當我打電話的方法。IOS - 如何強制視圖到風景

當我的方法運行我打電話:

[self shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)UIInterfaceOrientationLandscapeRight]; 

方法自轉

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); 
} 

的問題是,認爲不要用力旋轉。是可以在模擬器上測試它,或只是在真實的設備中工作?

回答

1
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES]; 
+0

泰克斯很多人!你釘了它! = D – 88fsantos

+0

我有一個問題。我在裏面創建的視圖沒有設置爲橫向:S現在它應該有480寬度和320高度,對吧?但它不:S – 88fsantos

+1

這聽起來像你需要創建一個相對大小的視圖。因此,不要使用'initWithFrame:CGRectMake(0,0,320,480)]'創建一個視圖,請嘗試像'initWithFrame:CGRectMake(0,0,[UIScreen mainScreen] .bounds.size.width,[UIScreen mainScreen] .bounds.size.height])' – Anthony