Making one specific class of view controller auto rotate in a tab bar app, but forcing all other classes of view controller to stay portrait

十年热恋 提交于 2019-12-01 22:52:58

问题


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


来源:https://stackoverflow.com/questions/4755263/making-one-specific-class-of-view-controller-auto-rotate-in-a-tab-bar-app-but-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!