Call both of After and Before Method in UIPageViewController when swim for forward in Swift 3 iOS

我的未来我决定 提交于 2019-12-04 22:04:08

It isn't a problem with the page view controller. It's a problem with your assumptions about when viewControllerBefore and viewControllerAfter are called. Your assumptions seem reasonable, but they are wrong, as I will now explain.

You are assuming, for example, that when I am in, say, page 3 and I start to swipe to page 4, viewControllerAfter is called for page 3 so that you can submit page 4. That is not true. The scroll implementation of page view controller uses caching and lookahead to make scrolling faster. Thus, when you do what I just described, it may be that page 4 has already been cached, and now, when the scroll ends, the PVC will call viewControllerAfter for page 5, in order to pre-cache it in case you scroll again the same way later. Or, if this is the last page, it may be that nothing will be called at all.

This behavior means that you cannot make any assumptions about when viewControllerBefore and viewControllerAfter are called or for what page they are called. But your code, with your use of notifications in those methods, depends upon such assumptions — and those assumptions are wrong, and that is why your code isn't working. Everything seems to you to be off-by-one — because it is.

You might be able to solve the problem by relying for your signals instead on the delegate methods willTransitionTo and didFinishAnimating (see the docs on UIPageViewControllerDelegate).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!