2012-07-09 153 views
1

我尝试手动旋转视图时出现问题。例如,我有一个视图控制器在横向上运行,并且我在该视图上有一个按钮。我想点击该按钮强制将视图旋转为纵向(倒置纵向)。我搜索但找不到答案。iphone:点击按钮将旋转视图

感谢您的帮助

+0

可以发布您遇到有问题的代码。 – Bazinga 2012-07-09 03:18:44

+0

对不起,这只是我的想法,我还没有代码。 – haisergeant 2012-07-09 03:33:39

+0

我给你一个答案。 – Bazinga 2012-07-09 03:35:23

回答

0

你可以试试这个:

- (void)buttonPressed { 

    // check current orientation 
    if ([[UIApplication sharedApplication] statusBarOrientation] != UIDeviceOrientationLandscapeLeft) { 

     // no, the orientation is wrong, we must rotate the UI 
     self.view.userInteractionEnabled = NO; 

     // setup status bar 
     [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO]; 
     // rotate main view, in this sample the view of navigation controller is the root view in main window 
     [self.view setTransform: CGAffineTransformMakeRotation(M_PI/2)]; 
     // set size of view 
     [self.view setFrame:CGRectMake(0, 0, 748, 1024)]; 

    } 

} 
+0

如何找出通用应用程序(iPhone 4/5,iPad/iPad视网膜/ iPad迷你)的帧大小? – peetonn 2013-08-11 01:45:51