Is there a documented way to set the iPhone orientation?

后端 未结 17 1286
清歌不尽
清歌不尽 2020-11-22 11:09

I have an app where I would like to support device rotation in certain views but other don\'t particularly make sense in Landscape mode, so as I swapping the views out I wou

17条回答
  •  日久生厌
    2020-11-22 11:39

    If you want to force it to rotate from portrait to landscape here is the code. Just note that you need adjust the center of your view. I noticed that mine didn't place the view in the right place. Otherwise, it worked perfectly. Thanks for the tip.

    if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
    
            [UIView beginAnimations:@"View Flip" context:nil];
            [UIView setAnimationDuration:0.5f];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
            self.view.transform = CGAffineTransformIdentity;
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
            self.view.bounds = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f);
            self.view.center = CGPointMake(160.0f, 240.0f);
    
            [UIView commitAnimations];
    }
    

提交回复
热议问题