3

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

编辑:基本上,控件总是横向的,但标签栏必须切换方向。这可能吗?

4

3 回答 3

1

对于您不希望控件重新调整的视图,请禁用 autoresizing: [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;
   }
}
于 2011-05-01T17:51:26.950 回答
0

景观示例

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

或者

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
于 2011-04-27T23:03:43.897 回答
0

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

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

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.

于 2011-05-01T19:13:16.633 回答