2010-11-18 64 views
1

我正在構建一個由RootViewController控制的多個UIViewController的應用程序。目前在plist中,應用程序默認爲LandscapeRight。iPhone:只有風景和只有肖像視圖的應用程序

可以說我有可以加載到RootViewController的以下文件:

  1. IntroView(景觀僅右)
  2. LandscapeView(景觀僅右)
  3. PortraitView(肖像ONLY)

我還在RootViewController的shouldAutorotateToInterfaceOrientation中添加了以下內容:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
if ([currentClass class] == PortraitView.class) { 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 

} else { 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

}

所以一切都很好,直到我在PortraitView並在viewWillAppear中加載我添加以下(類似於this thread

if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { //UIInterfaceOrientationLandscapeRight) {  

    self.view.transform = CGAffineTransformIdentity; 
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); 
    self.view.bounds = CGRectMake(0.0, 0.0, 320, 480); 
    self.view.center = CGPointMake(240.0f, 160.0f); 

} 


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 

這將產生正確加載PortraitView但現在我的問題是在我的PortraitView內,我有2個子視圖,我想在它們之間翻轉,但是因爲我旋轉了我的視圖,UIViewAnimationTransitionFlipFromLeft實際上使它從上到下翻轉而不是從左到右。我不能爲我的生活弄清楚如何在肖像中告訴PortraitView。

當我檢查[[UIDevice currentDevice]方向];它在景觀中告訴我它。當我嘗試使用shouldAutorotateToInterfaceOrientation並將其設置爲只有肖像時,它會旋轉我的視圖,使其不再正確。

希望這是有道理的!一直在看這個問題。

謝謝!

+0

RootViewController的超類是什麼?它只是一個普通的UIViewController? – 2010-11-18 22:43:37

+0

是的,只是一個UIViewController。我沒有使用任何導航欄或標籤欄。 – 2010-11-18 22:47:38

回答

0

我遇到了稍微不同的問題;橫向模式下的一個UIViewController子類,它從上到下而不是從左到右交換。

我工作的修復方法是將所有視圖添加到單個「內部」視圖,然後翻轉,而不是UIViewController的正常view

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight 
          forView:[self innerView] 
          cache:YES]; 

[self innerView][self view]唯一的孩子,和所有的子視圖在其內部。