Keeping controls in landscape mode but allowing ui

2019-07-03 23:47发布

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?

3条回答
小情绪 Triste *
2楼-- · 2019-07-04 00:13

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;
   }
}
查看更多
▲ chillily
3楼-- · 2019-07-04 00:33

example of Landscape

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

OR

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
查看更多
Luminary・发光体
4楼-- · 2019-07-04 00:35

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.

查看更多
登录 后发表回答