問(wèn)題描述
我的應(yīng)用遇到了一個(gè)小問(wèn)題.
I'm running into a small issue in my app.
我本質(zhì)上在 UIScrollView
中添加了一系列 UIButtons
作為子視圖,該 UIScrollView
是 nib 的一部分.每次我點(diǎn)擊一個(gè)按鈕時(shí),在按鈕被突出顯示之前都會(huì)有一個(gè)明顯的延遲.在按鈕變暗并顯示為選中之前,我基本上必須按住它大約半秒鐘.
I essentially have a series of UIButtons
added as subviews in a UIScrollView
which is part of a nib. Every time I tap on a button there is a noticeable delay before the button is highlighted. I essentially have to hold it for about half a second before the button dims and appears selected.
我假設(shè)這是因?yàn)?UIScrollView
需要確定觸摸是滾動(dòng)還是用于子視圖的觸摸.
I'm assuming this is because the UIScrollView
needs to determine if the touch is a scroll or if it's a touch that is meant for a subview.
無(wú)論如何,我有點(diǎn)不確定如何進(jìn)行.我只是希望按鈕在我點(diǎn)擊后立即顯示為選中狀態(tài).
Anyways, I'm a little unsure on how to proceed. I simply want the button to appear selected as soon as I tap it.
感謝任何幫助!
我嘗試將 delaysContentTouches
設(shè)置為 NO,但滾動(dòng)幾乎變得不可能,因?yàn)槲业拇蟛糠?scrollView 都充滿了 UIButtons
.p>
I've tried setting delaysContentTouches
to NO but scrolling becomes almost impossible since a majority of my scrollView is filled with UIButtons
.
推薦答案
好的,我已經(jīng)通過(guò)繼承 UIScrollView
并覆蓋 touchesShouldCancelInContentView
Ok I've solved this by subclassing UIScrollView
and overriding touchesShouldCancelInContentView
現(xiàn)在我的 UIButton
被正確標(biāo)記為 99 高亮并且我的滾動(dòng)視圖正在滾動(dòng)!
Now my UIButton
that was tagged as 99 highlights properly and my scrollview is scrolling!
myCustomScrollView.h:
@interface myCustomScrollView : UIScrollView {
}
@end
和myCustomScrollView.m:
@implementation myCustomScrollView
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
NSLog(@"touchesShouldCancelInContentView");
if (view.tag == 99)
return NO;
else
return YES;
}
這篇關(guān)于UIScrollView 中的 UIButton 觸摸延遲的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!