簡體   English   中英

動畫時按住按鈕時,UIPageViewController崩潰

[英]UIPageViewController crashes when holding down a button while it's animating

我有以編程方式設置動畫的UIPageViewController。 問題在於其中的視圖控制器內部具有UIButtons。 當我按住一個按鈕並等待UIPageViewController動畫時,該應用程序崩潰並顯示以下錯誤:

'Failed to determine navigation direction for scroll'

我想我需要做的是以某種方式偽造用戶在UIPageviewController動畫之前釋放按鈕。

但是, [self.button sendActionsForControlEvents:UIControlEventTouchCancel]; 似乎並不能解決問題。 UIControlEventTouchUpInside也沒有。

有更好的方法嗎?還是我使用sendActionsForControlEvents錯誤?

sendActionsForControlEvents:所做的所有操作都是調用您已分配給為按鈕傳遞的控件事件的任何方法。 它不會調用任何內部方法來以編程方式提升觸摸感或諸如此類。

在以編程方式為頁面視圖控制器設置動畫之前,請嘗試使用此方法有效地取消對頁面視圖控制器內部滾動視圖的平移手勢識別器的任何觸摸:

- (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;
        }
    }
}

(請注意,這與UIPageViewController的內部視圖層次結構混淆在一起,因此此方法有點丑陋,將來可能會中斷。我通常不建議這樣做,但我認為在這種情況下應該可以。 )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM