使一类特定的视图控制器在选项卡栏应用程序中自动旋转,但强制所有其他类的视图控制器保持纵向

发布于 2024-10-13 00:28:48 字数 652 浏览 2 评论 0原文

我有一个带有此代码的选项卡栏控制器,

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぶ宁プ宁ぶ 2024-10-20 00:28:48

您可以通过以下方式实现此目的:

  1. 将 statusBar 方向设置为 viewWillAppearviewWillDisappear

-(void) viewWillAppear:(BOOL)animated {
[超级viewWillAppear:动画];
[[UIApplication shareApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight];
}

-(void) viewWillDisappear:(BOOL)animated {
[超级viewWillDisappear:动画];
[[UIApplication共享应用程序] setStatusBarOrientation: UIInterfaceOrientationPortrait];
}

并手动旋转视图:self.view.transform = CGAffineTransformMakeRotation(M_PI/2);

  1. 呈现该视图模式将触发 shouldAutorotateToInterfaceOrientation 方法

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文