1

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

感谢您的帮助

4

1 回答 1

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)];

    }

}
于 2012-07-09T03:24:35.333 回答