gpt4 book ai didi

iphone - UIPageViewController 有时会在没有动画的情况下进行转换。为什么?

转载 作者:行者123 更新时间:2023-12-03 21:17:43 26 4
gpt4 key购买 nike

我有一个图书应用程序,它使用 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;
}
}

最佳答案

我认为这是因为你的台词:

[data setCurrentPage:currentIndex-1]; 

在您的 viewControllerBeforeViewController:viewControllerAfterViewController: 函数中。

这些函数只需要返回一个合适的viewController。更改当前 Controller 和播放动画的工作不是您的,而是 UIPageViewControllerDataSource 委托(delegate)的。如果自己设置的话就没有动画

关于iphone - UIPageViewController 有时会在没有动画的情况下进行转换。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9186495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com