Making one specific class of view controller auto

2019-02-24 23:49发布

问题:

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.

Can anyone tell me what I'm doing wrong?

回答1:

You could accomplish this by:

  1. setting statusBar orientation to 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]; }

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

  1. presenting that view modaly will trigger shouldAutorotateToInterfaceOrientation method