問題描述
我在 UIScrollView 中有一些 UIButton,但我不想延遲按鈕的觸摸.但是,一旦滾動(dòng)視圖檢測(cè)到拖動(dòng)/滾動(dòng),我想取消 UIButton 觸摸并繼續(xù)滾動(dòng) UIScrollView.
I have some UIButtons within a UIScrollView, but I do not want to delay the button touches. However, as soon as the scroll view detects a drag/scroll, I want to cancel the UIButton touch and proceed with the scrolling of the UIScrollView.
我已包含以下內(nèi)容...
I have included the following...
_scrollView.delaysContentTouches = NO;
...但是(顯然)按鈕觸摸在拖動(dòng)時(shí)不會(huì)取消.有人對(duì)我如何實(shí)現(xiàn)此功能有任何建議嗎?
...but (obviously) the button touch does not cancel when dragged. Does anyone have any suggestions as to how I can implement this functionality?
推薦答案
你可以重寫UIScrollView
的這個(gè)方法.
You can override this method of UIScrollView
.
-(BOOL)touchesShouldCancelInContentView:(UIView *)view
{
return YES;
}
在你的 UIButton 中,你應(yīng)該為不同的控件事件添加不同的方法.
And in your UIButton, you should add different method for different control events.
- 顯示
UIControlEventTouchDown
的高亮效果. UIControlEventTouchUpInside 的觸發(fā)按鈕 |UIControlEventTouchUpOutside
;- 清除
UIControlEventTouchCancel
的高亮效果.
- show highlight effect for
UIControlEventTouchDown
. - trigger button for
UIControlEventTouchUpInside | UIControlEventTouchUpOutside
; - clear highlight effect for
UIControlEventTouchCancel
.
這篇關(guān)于iOS UIScrollView取消UIButton觸摸滾動(dòng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!