Keeping controls in landscape mode but allowing uitabbar to switch

拟墨画扇 提交于 2019-12-12 14:16:39

问题


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?


回答1:


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;
   }
}



回答2:


example of Landscape

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

OR

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



回答3:


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.



来源:https://stackoverflow.com/questions/5811373/keeping-controls-in-landscape-mode-but-allowing-uitabbar-to-switch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!