在父视图控制器里面写如下代码

-(void)setViewOrientation:(UIInterfaceOrientation )orientation
{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        [[UIDevice currentDevice] performSelector:@selector(setOrientation:)
                                       withObject:(id)orientation];
    }
    [UIViewController attemptRotationToDeviceOrientation];//这句是关键
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return toInterfaceOrientation==UIInterfaceOrientationPortrait;
}

在子视图控制器的加入,这里子视图控制器要横屏

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear :YES];
    [self setViewOrientation:UIInterfaceOrientationLandscapeRight];
}
//重写下面子类的方法

- (NSUInteger) supportedInterfaceOrientations{

    returnUIInterfaceOrientationMaskLandscapeRight;

}

 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0){

    return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

 

 

相关文章:

  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2022-03-06
  • 2021-09-25
相关资源
相似解决方案