How to force view controller orientation in iOS 8?

前端 未结 25 2389
太阳男子
太阳男子 2020-11-22 13:11

Before iOS 8, we used below code in conjunction with supportedInterfaceOrientations and shouldAutoRotate delegate methods to force app orie

25条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 13:28

    According to solution showed by @sid-sha you have to put everything in the viewDidAppear: method, otherwise you will not get the didRotateFromInterfaceOrientation: fired, so something like:

    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
        if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
            NSNumber *value = [NSNumber numberWithInt:interfaceOrientation];
            [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
        }
    }
    

提交回复
热议问题