iphone:点击按钮将旋转视图

时间:2012-07-09 03:17:14

标签: iphone rotation uiinterfaceorientation

尝试手动旋转视图时遇到问题。例如,我有一个在横向运行的视图控制器,我在该视图上有一个按钮。我想点击该按钮强制视图旋转为纵向(颠倒肖像)。我搜索但找不到答案。

感谢您的帮助

1 个答案:

答案 0 :(得分: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)];

    }

}