容器视图控制器中UIPageViewController的旋转
我有一个包含其他ViewControllers的UIViewController。初始视图控制器设置在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;
此容器控制器已经实施automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers返回YES。它还实施manualy正向旋转改变非活跃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];
}
}
当菜单按钮被窃听我做ViewControllers之间的过渡。
- (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和UIPageViewControllerDataSource设置为此SecondCV和pageViewController:spineLocationForInterfaceOrientation:我回UIPageViewControllerSpineLocationMin的肖像和UIPageViewControllerSpineLocationMid景观。此SecondVC的旋转功能在其处于活动状态时正常工作 - 在横向上有两页,在纵向模式下正确显示了一页。但是当这个SecondVC不活跃时,旋转是不正确的。即使调用了pageViewController:spineLocationForInterfaceOrientation:,纵向和横向模式中仍然有一个页面。我试图解决这一段时间,但我没有看到任何其他选项。你有什么想法如何解决这个问题?
谢谢。
我已经解决了这种棘手的问题。
其实SecondVC旋转正确,或至少,脊柱位置正确更改。因此,当我旋转设备并且SecondVC在父视图中未处于活动视图控制器时,其HAS收到旋转消息并且pageViewController:spineLocationForInterfaceOrientation:也被调用。我为新的界面方向设置了正确的脊柱位置,并将其设置为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;
}
我知道我在做同样的事情两次,但多数民众赞成我愿意在这种情况下要付出的代价。为什么在调用pageViewController:spineLocationForInterfaceOrientation:并为Landscape设置两个视图控制器时,当SecondVC处于非活动状态时,在激活SecondVC之后,只有一个ViewController在m_pageController中的viewWillAppear:为我保留了一个谜。
我包括下面的代码在iOS 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;
}
希望它可以帮助别人!
我也使用页面视图控制器,我已经添加了VC到一个数组,但不知道过渡各种VC的正确方式,我如何移动到下一个VC使用页面卷曲转换。你可以请指导我或发布一些示例代码。 – 2012-11-28 07:11:57
[链接](https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html)我想你可以在这里找到所有的想法,如果没有,请联系我 – DaNY 2012-12-06 10:48:44
我还没有解决方案,请看看我的问题,如果你能指导我。 “http://*.com/questions/13776894/uipageviewcontroller-change-from-two-page-mode-to-one-page-mode-without-changi#comment18942540_13776894” – 2012-12-08 11:44:18