除了继承你的tabBarController因为你是压倒一切的houldAutorotateToInterfaceOrientation,你必须做到以下几点:
在其中要添加一个视图控制器的viewDidLoad方法来进行旋转:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
加入旋转控制器要在其中添加视图此委托方法:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
//NSLog(@"didRotateFromInterfaceOrientation");
if((fromInterfaceOrientation == UIInterfaceOrientationPortrait) ||
(fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
{
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate.tabBarController.view addSubview: viewToBeRotated];
[viewToBeRotated setHidden:NO];
return;
}
if(fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[viewToBeRotated removeFromSuperview];
[self.view setHidden:NO];
}
}
您可能还需要添加下面的方法:
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
//self.view = self.portrait;
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[viewToBeRotated removeFromSuperview];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate.tabBarController.view addSubview: viewToBeRotated];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//self.view = self.portrait;
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[viewToBeRotated removeFromSuperview];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
YourAppDelegate *mainDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate.tabBarController.view addSubview: viewToBeRotated];
mainDelegate.tabBarController.view.transform = CGAffineTransformIdentity;
mainDelegate.tabBarController.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
mainDelegate.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
}
你也可能想看看
Rotating the iPhone, and instantiating a new UIViewController
TabBarController and navigationControllers in landscape mode
实际上,我换出两种观点。我尝试设置autoResizingMask,但它仍然不起作用。您建议的其他两种方法应该由my - willAnimateFirstHalfOfRotationToInterfaceOrientation方法处理。它根据方向交换self.view。这个方法甚至都不会被调用。 – Rob 2009-06-15 23:23:42