开发者

Keeping controls in landscape mode but allowing uitabbar to switch

I have a UITabBar switches places when the iphone changes orientation an开发者_StackOverflowd 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?


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


example of Landscape

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

OR

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜