Locking device orientation on a view fails when going back in NavBar

谁说胖子不能爱 提交于 2019-12-06 04:17:25
Korey Hinton

I think I was able to replicate the scenario you described. Unfortunately the normal ways I try to force it to update didn't work but I did find this SO answer that seems to work. Put this in the view controller you return back to in viewDidAppear:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    let value = UIInterfaceOrientation.Portrait.rawValue
    UIDevice.currentDevice().setValue(value, forKey: "orientation")
}

This fix seemed to work for me. It is a pretty rough transition though. I hope that helps

I had this problem with presented view controllers and orientation lock differences. I added this into the "unlocked" controller:

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self willRotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft duration:0];
}

So when that controller is about to be removed (back button pressed) it sends a message that it should return to landscape (it doesn't matter left or right because the pervious controller will autorotate from that to the proper orientation). That's in objective-c, but I'm sure there is an analogous operation in swift. You may have to mess with the animation duration if it makes things look weird, but mine worked perfectly with an immediate switch.

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