2012-06-26 2 views
2

내 상황은 this question과 매우 유사합니다. 나는 iPhone이 세로 방향이고 iPad가 Landscape에 있고 어디에서나 appDelegate.window.rootViewController = newScreen;을 사용하여 모든 주요 화면 사이를 전환하는 보편적 인 앱을 가지고 있습니다. iPhone 앱이 완벽하게 작동합니다. iPad 앱은 때로 풍경이 아닌 세로 방향으로 스크린을 던질 것입니다.rootViewController가 설정되었지만 잘못된 방향으로 표시됩니다.

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 
      ViewController* v = nil; 
      if (IS_IPAD()) { 
       v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil]; 
      }else{ 
       v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
      } 
      [appDelegate.window setRootViewController:(UIViewController*)v]; 

가 나는 또한 this other question에서이 시도 : 다음은 몇 가지 샘플 전이 코드

AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 
      ViewController* v = nil; 
      if (IS_IPAD()) { 
       v = [[ViewController alloc] initWithNibName:@"ViewController-iPad" bundle:nil]; 
      }else{ 
       v = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
      } 

      [UIView 
      transitionWithView:appDelegate.window 
      duration:0.5 
      options:UIViewAnimationOptionTransitionCrossDissolve 
      animations:^(void) { 
       BOOL oldState = [UIView areAnimationsEnabled]; 
       [UIView setAnimationsEnabled:NO]; 
       [appDelegate.window setRootViewController:(UIViewController*)v]; 
       [UIView setAnimationsEnabled:oldState]; 
      } 
      completion:nil]; 

그러나 아무것도를 해결하지 않았다.

[appDelegate.window makeKeyAndVisable] 및 [appDelegate.window makeKeyWindow]를 사용하여 올바른 방향으로 '충격을 주길'바랍니다.

+1

이것은 이전에 본 적이없는 뷰 컨트롤러를 전환하는 독특한 방법이지만 작동 할 수 있습니다. 뷰 컨트롤러에 적절한'- (BOOL) shouldAutorotateToInterfaceOrientation :'을 추가 했습니까? 그것은 인터페이스 방향이 결정되는 장소 여야합니다. – mvds

+0

나는 정말로했다. 다음과 같이 보입니다. if (IS_IPAD()) { return UIInterfaceOrientationIsLandscape (interfaceOrientation); } return (interfaceOrientation == UIInterfaceOrientationPortrait); –

+0

흠. 덜 엄격한 VC 전환 방법으로 전환 할 수 있습니다 (예 : 고정 된 (빈)보기 컨트롤러를 사용하고 다양한보기를 모달로 표시합니다. 이렇게하면 인터페이스 방향이 더 안정적으로 고정 될 수 있습니다. – mvds

답변

4

나는 그것을 얻었습니다!

다음은 내 전환 블록의 모습입니다. 내가 한 핵심은 CALayer에서 변환 (실제 회전을하는 것)을 복사하는 것입니다. 파일 상단에 Quartz 프레임 워크와 #import <QuartzCore/QuartzCore.h>을 포함시켜야합니다.

[UIView transitionWithView:self.window 
        duration:0.5 
        options:UIViewAnimationOptionTransitionCrossDissolve 
       animations:^{       
    BOOL oldState = [UIView areAnimationsEnabled]; 
    [UIView setAnimationsEnabled:NO]; 
    target.view.layer.transform = window.rootViewController.view.layer.transform; 
    window.rootViewController = target; 
    [UIView setAnimationsEnabled:oldState]; 
} completion:nil]; 
+1

그걸 수정 한 것 같습니다! 정말 고맙습니다!!! –

+0

우수 수정, 많이 감사드립니다! –