使一类特定的视图控制器在选项卡栏应用程序中自动旋转,但强制所有其他类的视图控制器保持纵向

2023-12-06

我有一个带有此代码的选项卡栏控制器

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //NSLog(@"object type %@"  ,nil);
    if([[self navigationController ] isKindOfClass:[UINavigationController class]])
        if([[[self navigationController] visibleViewController] isKindOfClass:[SLImageViewController class]])
            return YES;
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

我需要 SLImageViewController 类的任何实例进行旋转,但不需要其他实例。我已经做了我能想到的一切,比如向我的 SLImageViewController 添加 return YES 和其他修复。

谁能告诉我我做错了什么?


您可以通过以下方式完成此操作:

  1. 将状态栏方向设置为viewWillAppear and viewWillDisappear

-(void) viewWillAppear:(BOOL)animated { [super viewWillAppear: animated]; [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight]; }

-(void) viewWillDisappear:(BOOL)animated { [super viewWillDisappear: animated]; [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait]; }

并手动旋转视图:self.view.transform = CGAffineTransformMakeRotation(M_PI/2);

  1. 呈现该视图模式将触发shouldAutorotateToInterfaceOrientation method
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使一类特定的视图控制器在选项卡栏应用程序中自动旋转,但强制所有其他类的视图控制器保持纵向 的相关文章

随机推荐