问题
I have a viewcontroller that's pushing another vc that should be in landscape mode but it does not autorotate to landscape when pushed ie. still in portrait.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
return NO;
}
When a popping the vc and back to the first controller all is perfect, it only displays in portrait mode only.
I can get the second vc to rotate by rotating the phone/emulator and then stick to the autorotate landscape. Then also perfect when popping, returns to portrait mode.
So is there any way to maybe progamaticly rotate the interface to landscape. Have tried using
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
But to no great success. Statusbar then stuck in landscape when popping.
回答1:
Use this in your viewDidLoad
method, it should work
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
[self.view setTransform:rotate];
CGRect contentRect = CGRectMake(0, 0, 480, 320);
self.view.frame = contentRect;
[self.view setCenter:CGPointMake(160.0f, 240.0f)];
来源:https://stackoverflow.com/questions/6492085/iphone-development-viewcontroller-portrait-to-landscape-no-autorotate