2

我有一个使用 UIPageViewController 导航其内容的图书应用程序。出于某种原因,有时我翻页(使用滑动手势),并且发生了转换,但没有动画。没有翻页动画,但新内容就在那里。

这是为什么?可能是因为我在后台进行了一些数据库调用,可能会弄乱 UI 动画吗?

谢谢

编辑:这是处理转换的代码

#pragma mark - UIPageViewControllerDataSource Methods

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController 
  viewControllerBeforeViewController:(UIViewController *)viewController
{
currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController labelContents]];
if(currentIndex == 0)
{
    return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.labelContents = [self.modelArray objectAtIndex:currentIndex - 1];

[data setCurrentPage:currentIndex-1];
return contentViewController;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
   viewControllerAfterViewController:(UIViewController *)viewController
{
currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController labelContents]];
if(currentIndex == self.modelArray.count-1)
{
    return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.labelContents = [self.modelArray objectAtIndex:currentIndex + 1];

[data setCurrentPage:currentIndex+1];


return contentViewController;
}

#pragma mark - UIPageViewControllerDelegate Methods

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
               spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if(UIInterfaceOrientationIsPortrait(orientation))
{
    //Set the array with only 1 view controller
    UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
    NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

    //Important- Set the doubleSided property to NO.
    self.pageViewController.doubleSided = NO;
    //Return the spine location
    return UIPageViewControllerSpineLocationMin;
}
else
{
    NSArray *viewControllers = nil;
    ContentViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];

     currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)currentViewController labelContents]];
    if(currentIndex == 0 || currentIndex %2 == 0)
    {
        UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
        viewControllers = [NSArray arrayWithObjects:currentViewController, nextViewController, nil];
    }
    else
    {
        UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
        viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil];
    }
    //Now, set the viewControllers property of UIPageViewController
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];

    return UIPageViewControllerSpineLocationMid;
}
}
4

1 回答 1

1

我认为这是因为您的线路:

[data setCurrentPage:currentIndex-1]; 

在你的viewControllerBeforeViewController:andviewControllerAfterViewController:函数中。

这些函数只需要返回一个合适的viewController。更改当前控制器和播放动画的工作不是你的,而是UIPageViewControllerDataSource委托的。自己设置的话就没有动画了

于 2012-06-05T04:10:02.680 回答