2012-12-11 3 views
0

세로보기가 포함 된 것과 가로보기가 포함 된 것을 제외하고 두 스토리 보드를 모두 만들었습니다.Xcode 4.5 및 iOS 6.x의 스토리 보드 오리엔테이션 지원?

내가 자동 크기 마스크를 사용하지 않기 때문에 완전히 가로 및 세로의 뷰 일부 변경의 레이아웃. 나는 수동으로 과거에 코드 뷰에 컨트롤을 이동 한하지만 난 쉬운 방법 후 내가 찾은 가장 가까운 솔루션 'benyboariu'출신이 시간 :

했다 - 여기

Storyboards orientation support for xCode 4.2? 코드입니다 iOS 5.x에서는 작동하지만 iOS 6.x에서는 작동하지 않는 것을 사용하고 있습니다.

- (void)updateLandscapeView 
{ 
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 

if (deviceOrientation == UIDeviceOrientationUnknown) 
{ 
    if ([[UIScreen mainScreen] bounds].size.height > [[UIScreen mainScreen] bounds].size.width) 
    { 
     deviceOrientation = UIDeviceOrientationPortrait; 
     self.appDelegate.isShowingLandscapeView = NO; 
    } 
    else 
    { 
     deviceOrientation = UIDeviceOrientationLandscapeLeft; 
     self.appDelegate.isShowingLandscapeView = YES; 
    } 
} 

if (UIDeviceOrientationIsLandscape(deviceOrientation) && !self.appDelegate.isShowingLandscapeView) 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard-Landscape" bundle:[NSBundle mainBundle]]; 
    UIViewController * landscape = [storyboard instantiateViewControllerWithIdentifier:@"RootViewController-Landscape"]; 
    self.appDelegate.isShowingLandscapeView = YES; 
    [UIView transitionWithView:landscape.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{ 
     self.view = landscape.view; 
    } completion:NULL]; 
} 
else if (UIDeviceOrientationIsPortrait(deviceOrientation) && self.appDelegate.isShowingLandscapeView) 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard-Portrait" bundle:[NSBundle mainBundle]]; 
    UIViewController * portrait = [storyboard instantiateViewControllerWithIdentifier:@"RootViewController"]; 
    self.appDelegate.isShowingLandscapeView = NO; 
    [UIView transitionWithView:portrait.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{ 
     self.view = portrait.view; 
    } completion:NULL]; 
} 
} 

아이폰 OS 6.x의에서 디버깅 할 때 내가 갖는 오류는 다음과 같습니다 인해, 이유는 'UIViewControllerHierarchyInconsistency'캐치되지 않는 예외 응용 프로그램 종료

가 : 'A보기가 기껏과 연관 될 수 있습니다 한 번에 하나의보기 컨트롤러! UIView보기 : 0x108276b0; 프레임 = (0, 0, 568, 268); 자동 크기 조절 = RM + BM; 애니메이션 = {위치 = CABasicAnimation : 0x10815c60; bounds = CABasicAnimation : 0x1082a5e0; }; layer = CALayer : 0x10827710은 RootViewController : 0x10821f10과 연결됩니다. 이보기를 RootViewController : 0x961a150과 연결하기 전에이 연관을 지우십시오. '

나는 보통 이러한 종류의 오류를 해결하기 위해 NIB에서보기 컨트롤러를 연결 해제하지만 스토리 보드에서는이를 수행 할 수 없습니다.

누구나 아이디어가 있습니까?

답변

0

음, 아이폰 OS 5.x 및 6.x의 작동이 솔루션을 마련했습니다이 문제를 시도하고 해결하는 방법의 모든 종류의 시도 후

기본적으로, 문제는 대신

self.view = landscape.view; 

또는

self.view = portrait.view; 

당신이 탐색 컨트롤러에 포함 된 모든 뷰 컨트롤러를 교체해야 할 일을 때문에 탐색 컨트롤러의 것으로 보인다, 그래서 스택. 나는 아래의 코드에서 뭘하는지

탐색 컨트롤러 스택의 모든 뷰 컨트롤러의있는 NSMutableArray를 만드는 것입니다. 그런 다음 각보기 컨트롤러를 반복하고보기 태그를 가져 와서 어떤보기를 바꿔야하는지 결정하십시오. 그런 다음 뷰 컨트롤러를 가로 또는 세로 버전으로 바꾸고 탐색 컨트롤러 뷰 컨트롤러 배열을 수정 된 배열로 설정하여 모든 뷰 컨트롤러를 대체합니다.

if (UIDeviceOrientationIsLandscape(deviceOrientation) && !self.appDelegate.isShowingLandscapeView) 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard-Landscape" bundle:[NSBundle mainBundle]]; 
    SearchViewController * landscape = [storyboard instantiateViewControllerWithIdentifier:@"SearchViewController-Landscape"]; 
    self.appDelegate.isShowingLandscapeView = YES; 
    [UIView transitionWithView:landscape.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{ 
     NSMutableArray * viewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]]; 
     if (viewControllers && [viewControllers count] > 0) 
     { 
      for (NSUInteger index = 0; index < [viewControllers count]; index++) 
      { 
       if ([[[viewControllers objectAtIndex:index] view] tag] == 1000) 
       { 
        RootViewController * root = [storyboard instantiateViewControllerWithIdentifier:@"RootViewController-Landscape"]; 
        [viewControllers replaceObjectAtIndex:index withObject:root]; 
       } 
       else if ([[[viewControllers objectAtIndex:index] view] tag] == 2000) 
       { 
        [viewControllers replaceObjectAtIndex:index withObject:landscape]; 
       } 
      } 

      [self.navigationController setViewControllers:viewControllers]; 
     } 
    } completion:NULL]; 
} 
else if (UIDeviceOrientationIsPortrait(deviceOrientation) && self.appDelegate.isShowingLandscapeView) 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard-Portrait" bundle:[NSBundle mainBundle]]; 
    SearchViewController * portrait = [storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"]; 
    self.appDelegate.isShowingLandscapeView = NO; 
    [UIView transitionWithView:portrait.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{ 
     NSMutableArray * viewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]]; 
     if (viewControllers && [viewControllers count] > 0) 
     { 
      for (NSUInteger index = 0; index < [viewControllers count]; index++) 
      { 
       if ([[[viewControllers objectAtIndex:index] view] tag] == 1000) 
       { 
        RootViewController * root = [storyboard instantiateViewControllerWithIdentifier:@"RootViewController"]; 
        [viewControllers replaceObjectAtIndex:index withObject:root]; 
       } 
       else if ([[[viewControllers objectAtIndex:index] view] tag] == 2000) 
       { 
        [viewControllers replaceObjectAtIndex:index withObject:portrait]; 
       } 
      } 

      [self.navigationController setViewControllers:viewControllers]; 
     } 
    } completion:NULL]; 
} 

내비게이션 컨트롤러에서 중첩 된보기에서이 기능을 사용하는 방법을 보여주기 위해 코드를 확장했습니다. 루트 뷰 컨트롤러에서 작업하는 경우 당신은 분명히이 사람을 도움이 단지 희망

인덱스 0에서 뷰 컨트롤러를 교체, 모든 뷰 컨트롤러를 통해 루프 필요가 없습니다!

+0

안녕하세요, 당신은 1000으로 무엇을 2000으로 설정합니까? – Jules

0
는 일반보기 (뷰 컨트롤러에서 그것을 가지고)에 Portait입니다 뷰 컨트롤러를 변경

. 이제 UIView로 인스턴스화하고 여러보기 컨트롤러와 관련되어 걱정하지 않고 전환을 수행 할 수 있어야합니다.

+0

나는 이미 스토리 보드의 컨트롤러에서 UIView를 제거하려고했지만 UIView 또는 UITableViewController가 아닌 UIViewController가 필요합니다. 즉, 컨트롤러가있을 수있는 것처럼 보입니다. –