在pageviewcontroller动画完成后更新当前页码 [英] Update current page number after pageviewcontroller animation is completed

查看:221
本文介绍了在pageviewcontroller动画完成后更新当前页码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是它在你转3或4页之后开始更新当前页码它开始更新当前页码从1,2,3,4,.....这是错误的。如果你以相反的顺序开始翻页,我们假设从12开始,那么它显示13然后从下一页开始以相反的顺序更新当前页码。

Problem having is that it start updating current page number after you turn 3 or 4 pages over then it start updating current page number starting from 1, 2, 3, 4,..... which is wrong. and if you start in reverse order turning page over lets suppose from 12 then it shows 13 and then from next page it starts updating current pagenumber in reverse order.

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed{


if (!completed) {

    return;
}
  if (currentIndex<totalPages -1 ){

  [self displaycurrentIndex:currentIndex + 1];

     }else if (currentIndex>totalPages + 1){

          [self displaycurrentIndex:currentIndex - 1];   
     } 
 }

- (void) displaycurrentIndex:(NSUInteger)currentIndex {

self.navigationItem.title = [NSString stringWithFormat:
                             @"Page %i of %i",
                            currentIndex + 1,
                             CGPDFDocumentGetNumberOfPages(PDFDocument)];
}

请帮助我们从一开始就修复此更新当前页码当按相反顺序进行时。

Please help in how to fix this updating current page number from the beginning and also when going in reverse order.

编辑:

删除后

if (!completed) {

return;
}

现在它在翻页后翻页,但现在更新当前页码20的20,然后是20的1,依此类推,但仍然以相反的顺序翻页时,它仍然以正向顺序更新当前页面编号,然后按相反的顺序更新。

Now it is Updating after turning first page over but now updates current page number from 0 of 20 and then 1 of 20 and so on but still when turning page over in reverse order it still updates current pagenumber in forward and then in reverse order.

谢谢你帮助。

推荐答案

根据我的经验(以及在过去的WWDC会议中确认的专用于本课程的视频)的最佳方式管理UIPageViewController中的页码是将页码信息直接存储在页面视图控制器中(即包含您要显示的单个页面的视图控制器中)。

From my experience (and also it is confirmed in the past WWDC session videos dedicated to this class) the best way to manage the page numbers in a UIPageViewController is to store as a property the page number information directly in the page view controller (that is in the view controller that contains the single page you want to show).

然后,如果要显示带有页码的通用状态栏,只需获取UIPageViewController的viewControllers属性,该属性根据UIPageViewController设置返回一个或两个视图控制器。

Then if you want to show a general purpose status bar with the page number, you simply fetch the viewControllers property of the UIPageViewController, which returns one or two view controllers depending on the UIPageViewController setup.

所以在伪代码中,当页面视图控制器询问其数据源时,新的视图控制器会显示你的代码:
- 将获得当前视图controller(s)
- 将从中获取(他们)页码
- 将计算下一个或上一页的页码(取决于页面卷曲/滑动方向)
- 将向数据源询问新计算的页码视图控制器,并将为其页码属性分配新值

So in pseudo-code when the page view controller asks its data source which are the new view controllers to display your code: - will get the current view controller(s) - will fetch from it (them) the page number - will calculate the next or prev page number(s) (depends on the page curl/swipe direction) - will ask to the data source for the new calculated page numbers view controllers and will assign to their page number property the new value

这样可以保护您免受奇怪的动画行为的影响并且您不需要在内存中保留一个全局currentIndex,这可能会导致问题,正如您所经历的那样。

In this way you are protected from strange animation behaviours and you don't need to keep in memory a global "currentIndex" which may lead to issues, as you experienced.

这篇关于在pageviewcontroller动画完成后更新当前页码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆