[英]UIPageViewController crashes when holding down a button while it's animating
I have UIPageViewController that animates programatically. 我有以编程方式设置动画的UIPageViewController。 The problem is that the view controllers inside it has UIButtons inside them.
问题在于其中的视图控制器内部具有UIButtons。 When I hold down a button and wait until the UIPageViewController animates, the app crashes with the error:
当我按住一个按钮并等待UIPageViewController动画时,该应用程序崩溃并显示以下错误:
'Failed to determine navigation direction for scroll'
What I think I need to do is to somehow fake that the user releases the button before the UIPageviewController animates. 我想我需要做的是以某种方式伪造用户在UIPageviewController动画之前释放按钮。
However, [self.button sendActionsForControlEvents:UIControlEventTouchCancel];
但是,
[self.button sendActionsForControlEvents:UIControlEventTouchCancel];
doesn't seem to do the trick. 似乎并不能解决问题。 Neither do
UIControlEventTouchUpInside
. UIControlEventTouchUpInside
也没有。
Is there a better way do to it or am I using sendActionsForControlEvents
wrong? 有更好的方法吗?还是我使用
sendActionsForControlEvents
错误?
All sendActionsForControlEvents:
does is call any methods you've assigned to the control events passed in for the button. sendActionsForControlEvents:
所做的所有操作都是调用您已分配给为按钮传递的控件事件的任何方法。 It doesn't call any internal methods to programmatically lift up touches or anything like that. 它不会调用任何内部方法来以编程方式提升触摸感或诸如此类。
Right before you programmatically animate your page view controller, try using this method to effectively cancel any touches on the pan gesture recognizer of the page view controller's internal scroll view: 在以编程方式为页面视图控制器设置动画之前,请尝试使用此方法有效地取消对页面视图控制器内部滚动视图的平移手势识别器的任何触摸:
- (void)cancelPanGestureTouchesOfPageViewController:(UIPageViewController *)pageVC
{
// Since UIPageViewController doesn't provide any API to access its scroll view,
// we have to find it ourselves by manually looping through its view's subviews.
for (UIScrollView *scrollView in pageVC.view.subviews) {
if ([scrollView isKindOfClass:[UIScrollView class]]) {
// We've found the scroll view, so use this little trick to
// effectively cancel any touches on its pan gesture recognizer
BOOL enabled = scrollView.panGestureRecognizer.enabled;
scrollView.panGestureRecognizer.enabled = !enabled;
scrollView.panGestureRecognizer.enabled = enabled;
}
}
}
(Note that this is messing with the internal view hierarchy of UIPageViewController
, so this method is kind of ugly and may break in the future. I generally don't recommend doing stuff like this, but I think in this instance it should be okay.) (请注意,这与
UIPageViewController
的内部视图层次结构混淆在一起,因此此方法有点丑陋,将来可能会中断。我通常不建议这样做,但我认为在这种情况下应该可以。 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.