2012-04-13 5 views
6

다른 ViewController가 포함 된 UIViewController가 있습니다. 초기의 ViewController가있는 viewDidLoad에 설정됩니다컨테이너 뷰 컨트롤러에서 UIPageViewController 회전

FirstViewController *first = [FirstViewController alloc] init]; 
first.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
first.view.frame = m_content.frame; 

[self addChildViewController:first]; 
[m_content.view addSubview:first.view]; 
[first didMoveToParentViewController:self]; 
m_activeViewController = first; 

이 컨테이너 컨트롤러는 YES 돌아 automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers을 구현했습니다. 또한 비 액티브 ViewControllers 메뉴 버튼 i가 ViewControllers 간의 전환을 도청

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    for(UIViewController *vc in m_viewControllers) 
    { 
     if(vc != [m_activeViewController] 
      [vc willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
    } 
} 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    for(UIViewController *vc in m_viewControllers) 
    { 
     if(vc != [m_activeViewController] 
      [vc didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
    } 
} 

에 정 회전 변화를 수동으로 실시하기 위해 구현되었다.

- (void)onMenuItemTapped:(id)sender 
{ 
    UIViewController *vc = [m_viewControllers objectAtIndex:sender.tag]; 

    vc.view.frame = m_content.frame; 
    [self addChildViewController:vc]; 
    [self transitionFromViewController:m_activeViewController toViewController:vc duration:0 options:UIViewAnimationOptionTransitionNone animations:nil completion:^(BOOL finished) { 
    [vc didMoveToParentViewController:self]; 
    [m_activeViewController removeFromParentViewController]; 
    m_activeViewController = vc; 
    }]; 
} 

이 전환은 내 "정상"ViewControllers 잘 동작하고 그들이 활성화되지 않은 경우에도, 방향 변경 후 제대로 표시됩니다. 그러나 SecondCV라는 하위보기 컨트롤러 중 하나는 하위보기 컨트롤러로 UIPageViewController입니다. 나는 UIPageViewControllerDelegate이 SecondCV에 UIPageViewControllerDataSource 세트를 가지고 pageViewController에 : spineLocationForInterfaceOrientation : 나는 풍경 세로 UIPageViewControllerSpineLocationMid에 대한 UIPageViewControllerSpineLocationMin을 반환합니다. 이 SecondVC의 회전 기능은 활성화되어있을 때 올바르게 작동합니다. 가로로 두 페이지가 있고 세로 모드로 한 페이지가 올바르게 표시됩니다. 그러나이 SecondVC가 활성화되어 있지 않으면 회전이 잘못되었습니다. pageViewController : spineLocationForInterfaceOrientation :이 호출 되더라도 세로 및 가로 모드 모두에서 한 페이지가 계속 존재합니다. 나는 이것을 얼마 동안 고치려고 노력하고있다. 그러나 나는 다른 옵션을 보지 못했다. 이 문제를 해결하는 방법에 대한 아이디어가 있습니까?

감사합니다.

답변

1

나는이 종류의 까다로운 문제를 해결했습니다.

실제로 SecondVC가 올바르게 회전되었거나 적어도 척추 위치가 올바르게 변경되었습니다. 따라서 장치를 회전하고 SecondVC가 부모보기에서 활성보기 컨트롤러가 아닌 경우 HAS 수신 된 순환 메시지 및 pageViewController : spineLocationForInterfaceOrientation :도 호출되었습니다. 새로운 인터페이스 방향에 맞는 정확한 위치를 설정하고 setViewControllers을 SecondVC의 페이지보기 컨트롤러에 지정했습니다. 문제는, 비록 두 개의 뷰 컨트롤러를 UIPageViewControllerSpineLocationMid으로 설정했다하더라도, SecondVC를 표시 한 후에 UIPageViewControllerSpineLocationMin과 같은 하나의 뷰 컨트롤러가 여전히 존재한다는 것입니다. 페이지 뷰 컨트롤러 척추 위치는 정확이 메서드를 호출 할 때하기 때문에, 다시와 내가 하나를 설정,이 정보를 기반으로 :

나는 viewWillAppear에서 페이지 뷰 컨트롤러에 뷰 컨트롤러를 설정하여 문제를 "해결"했다 또는 두 페이지 (뷰 컨트롤러)

- (void)viewWillAppear:(BOOL)animated 
{ 
if(m_pageController.spineLocation == UIPageViewControllerSpineLocationMid) 
{ 
    LeftPageController *left; 
    RightPageController *right; 
    if(m_pageController.viewControllers.count > 0) 
    { 
     left = [m_pageController.viewControllers objectAtIndex:0]; 

     right = [m_storyboard instantiateViewControllerWithIdentifier:@"rightPage"]; 
     [right loadView]; 
    } 

    [m_pageController setViewControllers:[NSArray arrayWithObjects:left, right, nil] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil]; 

    [m_left hideGallery]; 
} 

if(m_pageController.spineLocation == UIPageViewControllerSpineLocationMin) 
{ 

    [m_pageController setViewControllers:[NSArray arrayWithObject:[m_pageController.viewControllers objectAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil]; 
} 

[super viewWillAppear:animated]; 
} 


- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation 
{ 
if(UIInterfaceOrientationIsPortrait(orientation)) 
{ 
    LeftPageController *left = [pageViewController.viewControllers objectAtIndex:0]; 
    [pageViewController setViewControllers:[NSArray arrayWithObject:left] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil]; 

    pageViewController.doubleSided = NO;  

    return UIPageViewControllerSpineLocationMin; 
} 

if(UIInterfaceOrientationIsLandscape(orientation)) 
{  
    LeftPageController *left; 
    RightPageController *right; 
    if(pageViewController.viewControllers.count > 0) 
    { 
     left = [pageViewController.viewControllers objectAtIndex:0]; 
     right = [m_storyboard instantiateViewControllerWithIdentifier:@"rightPage"]; 
     [right loadView]; 
    } 

    [pageViewController setViewControllers:[NSArray arrayWithObjects:left,right, nil] direction:UIPageViewControllerNavigationDirectionForward | UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil]; 

    return UIPageViewControllerSpineLocationMid; 
} 

return UIPageViewControllerSpineLocationMin; 
} 

난 내가 두 번 같은 일을하고있는 중이 야 알고,하지만 난이 경우 지불 기꺼이 가격을 이잖아. spineLocationForInterfaceOrientation : pageViewController 호출 한 후 왜 SecondVC이 비활성 상태 일 때을하고 풍경이보기 컨트롤러를 설정, viewWillAppear에서 m_pageController에 하나의 ViewController입니다 : 활성화 한 후 SecondVC 나를 위해 비밀을 유지됩니다.

+0

페이지 뷰 컨트롤러도 사용하고 있으며 VC에 배열을 추가했지만 다양한 VC의 전환 방법을 알지 못해 어떻게 다음 VC가 페이지 컬 전환을 사용하여 이동할 수 있습니까? 제발 저를 안내하거나 샘플 코드를 게시 할 수 있습니까? –

+0

[link] (https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html) 여기에 everythink를 찾을 수 있다고 생각합니다. 그렇지 않다면 저에게 연락하십시오. – DaNY

+0

아무 것도 없습니다. 솔루션을 아직 제발 나를 안내 할 수 있다면 제 질문을보십시오. "http://stackoverflow.com/questions/13776894/uipageviewcontroller-change-from-two-page-mode-to-one-page-mode-without-changi#comment18942540_13776894" –

0

나는 아이폰 OS 6에서이 문제를 해결하기 위해 코드를 다음 포함 :

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation 
{ 

    NSArray *allPageControllers = pageViewController.viewControllers 

    if (allPageControllers != nil) { 
     [self setViewControllers:allPageControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 
    } 

    else { 

     UIViewController *defaultViewController = [[UIViewController alloc] init]; 
     [self setViewControllers:[NSArray arrayWithObject:defaultViewController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; 
     [defaultViewController release]; 
    } 

    return UIPageViewControllerSpineLocationMin; 
} 

은 사람을 도움이되기를 바랍니다!