使一类特定的视图控制器在选项卡栏应用程序中自动旋转,但强制所有其他类的视图控制器保持纵向
我有一个带有此代码的选项卡栏控制器,
- (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 类的任何实例来旋转,但其他都不需要。我已经做了我能想到的一切,比如向我的 SLImageViewController 添加 return YES 和其他修复。
谁能告诉我我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过以下方式实现此目的:
viewWillAppear
和viewWillDisappear
-(void) viewWillAppear:(BOOL)animated {
[超级viewWillAppear:动画];
[[UIApplication shareApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
}
-(void) viewWillDisappear:(BOOL)animated {
[超级viewWillDisappear:动画];
[[UIApplication共享应用程序] setStatusBarOrientation: UIInterfaceOrientationPortrait];
}
并手动旋转视图:
self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
shouldAutorotateToInterfaceOrientation
方法You could accomplish this by:
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);
shouldAutorotateToInterfaceOrientation
method