ViewController has wrong orientation after Landscape-only has been popped

放肆的年华 提交于 2019-12-22 10:48:12

问题


In a navigation-based app, LandscapeViewController only supports landscape mode (all others support both modes). I also have a "loading screen" that advises the user to rotate the phone before continuing. This way I can make sure that when my landscape view loads, that it's in landscape mode.

The problem comes when I rotate the phone to portrait mode while still showing LandscapeVC. I press the Back navigation button to navigate up one level (to a VC that supports both landscape and portrait modes), but the upper level shows in landscape mode even though the phone is in portrait mode. I guess this is because when I left this view I was in portrait mode, I then rotated the phone while in another view, so this view has not received the notification. If I then proceed to rotate the phone to the other landscape mode (say the LandscapeVC was loaded on its right side, so I'd rotate the upper VC from portrait to the left landscape mode), it will update.

My question is: how can I notify this upper view that the phone was rotated, so when the user goes up after putting the phone in portrait mode, the upper view shows correctly?


回答1:


Where you pop the sub-view off the stack and return to the previous view (currently stays in landscape, you'd like in portrait), you could try sending it to the setNeedsLayout selector.




回答2:


Please try this,

This may help you.

All the best

- (BOOL) shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)interfaceOrientation {
    if (interfaceOrientation == UIInterfaceOrientationPortrait)
        return NO;
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft )
        return YES; 
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


来源:https://stackoverflow.com/questions/2093821/viewcontroller-has-wrong-orientation-after-landscape-only-has-been-popped

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