問題描述
我有一個帶有一行按鈕的水平滾動視圖.除非我非常快速地滑動,否則滾動視圖不會滾動.
I have a horizontal scroll view with a line of buttons. The scroll view will not scroll unless I do an extremely fast swipe.
如果我將按鈕設置為 userInteractionEnabled = NO,則滾動按預期工作,但當然,按鈕根本不起作用.
If I set the buttons to userInteractionEnabled = NO, then the scrolling works as expected, but of course, then the buttons don't work at all.
此應用在 iOS 7 及之前的版本中運行良好.這似乎是 iOS 8 的功能".我確實注意到我可以捕獲按鈕的拖動事件,但我不知道如何將其重定向回滾動視圖.
This app worked fine in iOS 7 and before. It seems to be a iOS 8 "feature". I did notice that I can catch the button's drag event, but I don't know how to redirect it back to the scrollView.
我想我需要用 UIView 替換我的按鈕并自己管理事件,但如果有人有其他想法或解決方案,我將不勝感激.
I'm thinking I'll need to replace my buttons with UIViews and manage the events myself but I'd be grateful if someone has other ideas or solutions.
推薦答案
我發現在 iOS 8 中,UIScrollView 的底層 UIPanGestureRecognizer 不尊重 UIScrollView 的 delaysContentTouches 屬性.我認為這是一個 iOS 8 錯誤.這是我的解決方法:
I found that in iOS 8, the UIScrollView's underlying UIPanGestureRecognizer is not respecting the UIScrollView's delaysContentTouches property. I consider this an iOS 8 bug. Here's my workaround:
theScrollView.panGestureRecognizer.delaysTouchesBegan = theScrollView.delaysContentTouches
這篇關于ios 8 - 水平滾動視圖中的按鈕攔截平移事件 - 滾動不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!