除了繼承你的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