简体   繁体   English

动画时按住按钮时,UIPageViewController崩溃

[英]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.

相关问题 当同级是UIPageViewController时,UITableView不进行动画处理 - UITableView not animating when sibling is a UIPageViewController AS3按住按钮时连续运行代码 - 适用于iOS / Android的Air - AS3 Run code continuously while holding a Button down - Air For iOS/Android 如何在动画时轻按按钮使按钮消失 - How to make a button disappear when it is tapped while it is animating ARC在导航控制器中“返回”时不释放内存 - 而且它正在减慢我的uipageviewcontroller - ARC not releasing memory when going “back” in navigation controller - and it's slowing down my uipageviewcontroller Swift:UIBarButtonItem仅通过按住按钮来调用操作以显示UIImagePickerController的界面 - Swift: UIBarButtonItem only calls action to display UIImagePickerController's interface by holding down the button iOS:按住按钮和手势识别 - iOS: holding down a button and gesture recognizing 使用ajax时,在iOS中按住文本不会显示jQueryMobile对话框上的“复制”按钮 - Holding down on text in iOS does not bring up the 'copy' button on jQueryMobile Dialog when using ajax UIPageViewController中的按钮 - Button in UIPageViewController UIPageViewController在内存不足时翻转过快时崩溃 - UIPageViewController crashes when flipped too fast during low memory UIPageViewController的subView不能对Subview进行动画处理? 斯威夫特4 - subView of UIPageViewController not animating Subview? Swift 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM