How to force view controller orientation in iOS 8?

前端 未结 25 2383
太阳男子
太阳男子 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条回答
  •  余生分开走
    2020-11-22 13:22

    This is a feedback to comments in Sid Shah's answer, regarding how to disable animations using:

    [UIView setAnimationsEnabled:enabled];
    

    Code:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:NO];
        [UIView setAnimationsEnabled:NO];
    
        // Stackoverflow #26357162 to force orientation
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
    
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:NO];
        [UIView setAnimationsEnabled:YES];
    }
    

提交回复
热议问题