iphone work 使一個特定類的視圖控制器自動在標籤欄應用程序中旋轉,但強制所有其他類的視圖控制器保持肖像



shouldautorotate swift 4 (1)

我有一個標籤欄控制器與此代碼

- (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類的任何實例來旋轉,但沒有其他人。 我已經做了我能想到的一切,如添加返回YES到我的SLImageViewController和其他修復。

誰能告訴我我做錯了什麼?


你可以做到這一點:

  1. 設置statusBar方向為viewWillAppearviewWillDisappear

-(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方法




autorotate