保持控件处于横向模式但允许 uitabbar 切换

发布于 2024-11-03 17:46:32 字数 137 浏览 0 评论 0原文

我有一个 UITabBar 在 iphone 改变方向时切换位置并且工作正常,但我希望第一个选项卡视图中的控件保持静态,无论手机的位置如何。 我觉得我错过了一些明显的东西?

编辑: 基本上,控件始终是横向的,但选项卡栏必须切换方向。这可能吗?

I have a UITabBar switches places when the iphone changes orientation and that works fine, but I want the controls within the view of the first tab to stay static regardless of the position of the phone.
I feel like I'm missing something obvious?

Edit:
Basically, the controls are always landscape but the tab bar must switch orientations. It this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

ぃ双果 2024-11-10 17:46:32

对于您不希望控件重新调整的视图,请禁用自动调整大小:[self.view setAutoresizesSubviews:NO];。这将阻止所有控件(子视图)响应界面方向更改,但选项卡仍会响应。您可能还需要设置当前视图的 autoresizingMask:[self.view setAutoresizingMask:UIViewAutoresizingNone];

添加:对您不想旋转的所有控件尝试以下操作

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
   switch (toInterfaceOrientation) {
      case UIInterfaceOrientationLandscapeLeft:
         label.transform = CGAffineTransformMakeRotation(M_PI_2); // 90 degress
         break;
      case UIInterfaceOrientationLandscapeRight:
         label.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2); // 270 degrees
         break;
      case UIInterfaceOrientationPortraitUpsideDown:
         label.transform = CGAffineTransformMakeRotation(M_PI); // 180 degrees
         break;
      default:
         label.transform = CGAffineTransformMakeRotation(0.0);
         break;
   }
}

For the view in which you don't want the controls to readjust, disable the autoresizing: [self.view setAutoresizesSubviews:NO];. This will prevent all controls (subviews) from responding to interface orientation changes and yet the tab will still respond. You might also have to set the autoresizingMask of the current view: [self.view setAutoresizingMask:UIViewAutoresizingNone];

Addition : try the following for all controls you don't want to rotate

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
   switch (toInterfaceOrientation) {
      case UIInterfaceOrientationLandscapeLeft:
         label.transform = CGAffineTransformMakeRotation(M_PI_2); // 90 degress
         break;
      case UIInterfaceOrientationLandscapeRight:
         label.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2); // 270 degrees
         break;
      case UIInterfaceOrientationPortraitUpsideDown:
         label.transform = CGAffineTransformMakeRotation(M_PI); // 180 degrees
         break;
      default:
         label.transform = CGAffineTransformMakeRotation(0.0);
         break;
   }
}
夏末 2024-11-10 17:46:32

的例子

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

景观或

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}

example of Landscape

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

OR

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
雅心素梦 2024-11-10 17:46:32

不幸的是,这并不完全简单。您不能让 UITabBarController 响应界面更改,同时不让内容视图控制器响应。

但有一种方法可以做到。在内容视图控制器的 willAnimateRotationToInterfaceOrientation:duration: 中,您可以对不想旋转的子视图应用相反的旋转(使用 transform 属性)。例如,UIInterfaceOrientationLandscapeLeft 是 90° 顺时针旋转,因此如果您对视图的 transform 应用 90° 逆时针旋转,它将看起来没有旋转。

如果需要,您可以将内容视图控制器的整个界面包含在 UIView 中,这样您只需反向旋转(并可能调整大小)该视图即可。我不知道在视图控制器的主视图上应用反向旋转是否有效,系统可能会覆盖您对该特定视图的设置。

Unfortunately, it's not exactly straightforward. You can't have the UITabBarController respond to interface changes while not having the content view controller respond.

But there is a way to do it. In the content view controller's willAnimateRotationToInterfaceOrientation:duration:, you can apply an opposite rotation (using the transform property) to the subviews that you don't want rotated. For example, UIInterfaceOrientationLandscapeLeft is a 90° clockwise rotation, so if you apply a 90° counterclockwise rotation to the view's transform it will seem to not have rotated.

If you want, you could include the entire interface of the content view controller in a UIView so you just have to counterrotate (and possibly resize) that one view. I don't know whether it would work to apply the counterrotation on the view controller's main view, the system may override your setting for that particular view.

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