Iphone development viewcontroller portrait to landscape no autorotate

南笙酒味 提交于 2019-12-11 14:03:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!