让一个特定的视图控制器类在标签栏应用程序中自动旋转,但是强制所有其他的视图控制器类保持竖屏

时间:2021-10-29 20:12:28

I have a tab bar controller with this code

我有一个带这些代码的标签栏控制器

- (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);
}

I need any instance of the SLImageViewController class to rotate, but none of the others. I have done everything i can think of like adding return YES to my SLImageViewController and other fixes.

我需要任何slim viewcontroller类的实例来旋转,但其他的都不需要。我已经完成了我能想到的所有事情,比如在我的瘦视图控制器和其他修复中添加return YES。

Can anyone tell me what I'm doing wrong?

有人能告诉我我做错了什么吗?

1 个解决方案

#1


3  

You could accomplish this by:

你可以通过:

  1. setting statusBar orientation to viewWillAppear and viewWillDisappear
  2. 将statusBar的方向设置为viewWillAppear和viewWillDisappear

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

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

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

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

and rotating a view manually: self.view.transform = CGAffineTransformMakeRotation(M_PI/2);

手动旋转视图:self。view。变换= CGAffineTransformMakeRotation(M_PI / 2);

  1. presenting that view modaly will trigger shouldAutorotateToInterfaceOrientation method
  2. 显示该视图modaly将触发shouldAutorotateToInterfaceOrientation方法

#1


3  

You could accomplish this by:

你可以通过:

  1. setting statusBar orientation to viewWillAppear and viewWillDisappear
  2. 将statusBar的方向设置为viewWillAppear和viewWillDisappear

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

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

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

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

and rotating a view manually: self.view.transform = CGAffineTransformMakeRotation(M_PI/2);

手动旋转视图:self。view。变换= CGAffineTransformMakeRotation(M_PI / 2);

  1. presenting that view modaly will trigger shouldAutorotateToInterfaceOrientation method
  2. 显示该视图modaly将触发shouldAutorotateToInterfaceOrientation方法