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
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?
You could accomplish this by:
- setting statusBar orientation to
viewWillAppear
andviewWillDisappear
-(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);
- presenting that view modaly will trigger
shouldAutorotateToInterfaceOrientation
method
精彩评论