看来UIPageViewController中存在一个问题,我无法解决下面的断言错误
断言失败 - [XXX.UIPagingViewController queuingScrollView:didEndManualScroll:toRevealView:direction:animated:didFinish:didComplete:],/ BuildRoot / Library / Cache / apple.xbs / Sources / UIKit / UIKit-3698.33.3.301 / UIPageViewController.m:2067
我已经查看了以下答案,以及更多,但我无法找出答案,但我相信我有一个不同的问题来隔离问题。
Assertion failure in UIPageViewController #1
Assertion failure in UIPageViewController #2
UIPageViewController didFinishAnimating not called if swiped quickly
在做了一些研究之后,根据我在黑客攻击解决方案中的发现,我想我会问一个与手头问题有关的更具体的问题
实施
我实现了UIPageViewController,以全屏方式垂直显示3个视图控制器。这是我的实现,然后是我的观察,以及我无法完全理解的黑客攻击解决方案。
UIPageViewControllerDataSource
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController?
{
if let viewController = viewController as? HomeItemPageViewController,
let index = viewControllers.index(of: viewController)
{
if index == 0 { return nil }
return viewControllerAtIndex(index: max(0, index - 1))
}
return nil
}
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController?
{
if viewControllers.count > 0
{
if let vc = viewController as? HomeItemPageViewController,
let index = viewControllers.index(of: vc), index + 1 < viewControllers.count
{
return viewControllerAtIndex(index: index + 1)
}
}
return nil
}
UIPageViewControllerDataSource
public func pageViewController(_ pageViewController: UIPageViewController, willTransitionTo pendingViewControllers: [UIViewController])
{
print("[PageViewController] - willTransitionTo - pendingViewControllers \(pendingViewControllers)")
}
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)
{
print("[PageViewController] - didFinishAnimating - finished \(finished) - completed \(completed) ")
}
情景1
我从控制器轻触到控制器,在每种情况下,willTransitionTo
和didFinishAnimating
都会相应地触发。
场景2
从第一页(索引0)滚动到中间页(索引1)后,我可以清楚地看到willTransitionTo
的来电,然后是didFinishAnimating
。
现在,如果我开始平移到下一个索引3,但是在动画到索引3之前将其释放,则只会调用willTransitionTo
。下一步是开始平移到索引0处的第一页,然后触发断言错误....
黑客解决方案(请在此处提供帮助)
通过以下方式对Assertion failue中的方法进行调整,我试图弄清楚它是如何被触发的,可能会隔离我可以做什么来强制手动完成转换。
final public class func swizzleMethods()
{
let original_method = class_getInstanceMethod(FlowPageViewController.self, Selector(("queuingScrollView:didEndManualScroll:toRevealView:direction:animated:didFinish:didComplete:")))
let swizzled_method = class_getInstanceMethod(FlowPageViewController.self, Selector(("_queuingScrollView:didEndManualScroll:toRevealView:direction:animated:didFinish:didComplete:")))
method_exchangeImplementations(original_method!, swizzled_method!)
}
@objc func _queuingScrollView(_ arg1: Any, didEndManualScroll arg2: Bool, toRevealView arg3: Any, direction arg4: Int, animated arg5: Bool, didFinish arg6: Bool, didComplete arg7: Bool)
{
print("[FlowPageViewController] - Swizzle Ignore")
}
我无法修复它,或者无法弄清楚我能做些什么来让代理人按照应有的方式执行didFinishAnimating
调用。但是从它出来的奇怪的观察结果,一旦这种方法被淘汰,我不称之为原始方法,一切看起来都应该没有任何后果。
我相信由于该方法是私有的,因此无法获得批准,所以我想知道是否有人知道如何强制UIPageViewController完成它的转换,或者我如何取消相对于居中的转换支持ScrollView中显示的视图?
对此的任何见解都将受到高度赞赏。