2012-10-08 69 views
1

我在我的應用程序中有一個視圖。我想在橫向顯示中顯示的特定視圖。 當用戶進入該視圖時,我想強制用戶更改設備方向。當用戶轉到其他視圖時,必須重置ti。我該怎麼做?如何將特定視圖的方向更改爲橫向?

+0

它僅適用於單個視圖嗎?這種觀點有多少次? –

+0

@VenkatManohar只有一次。意思是當用戶點擊一個按鈕時,viewController將被加載,所以當它被加載時,我想改變方向。 – user1244311

+0

[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];您希望將哪個方向放在那裏......它的工作原理 –

回答

1

我得到了答案

[UIApplication的sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]。

float angle = M_PI/2; //rotate 180°, or 1 π radians 
self.view.layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0); 
+0

它可能正常工作,但它不是正確的解決方案。 –

+0

@AndreyChevozerov:那麼如何得到它? – user1244311

+0

請參閱下面的答案。 –

3

在它的視圖控制器實現了兩個消息:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

而這一切。

相關問題