Force landscape orientation in one view controller

北城余情 提交于 2019-12-06 10:28:59
Andrey Finayev

Had the same problem and managed to fix it by dismissing the presented modal view animated:YES.

[self dismissViewControllerAnimated:YES completion:nil];

Hope that helps!

My solution involves what Andrey Finayev suggested, but also I had to set another transition style otherwise I was getting blank screen after the dismiss animation finished.

UIViewController *mVC = [[UIViewController alloc] init];
mVC.modalPresentationStyle = UIModalPresentationFullScreen;
mVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:mVC animated:NO completion:^{
    [self.navigationController dismissViewControllerAnimated:YES completion:^{

    }];
}];

To prevent the little "flashing" from mdonia solution, I added a dispatch_after and was able to dismiss the dummy modal viewController with animation:NO

UIViewController *dummyModalVC = [UIViewController new];
[dummyModalVC setModalPresentationStyle:UIModalPresentationFullScreen];
[dummyModalVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[dummyModalVC.view setBackgroundColor:[UIColor purpleColor]];

[self presentViewController:dummyModalVC animated:NO completion:^{
    double delayInSeconds = 0.001f;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [dummyModalVC dismissViewControllerAnimated:NO completion:^{}];
    });
}];

Looks of course still like an ugly workaround, but I didn't found a better solution in the given time… ;(

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