問題描述
我的應用遇到了一個小問題.
I'm running into a small issue in my app.
我本質上在 UIScrollView
中添加了一系列 UIButtons
作為子視圖,該 UIScrollView
是 nib 的一部分.每次我點擊一個按鈕時,在按鈕被突出顯示之前都會有一個明顯的延遲.在按鈕變暗并顯示為選中之前,我基本上必須按住它大約半秒鐘.
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.
我假設這是因為 UIScrollView
需要確定觸摸是滾動還是用于子視圖的觸摸.
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.
無論如何,我有點不確定如何進行.我只是希望按鈕在我點擊后立即顯示為選中狀態.
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
設置為 NO,但滾動幾乎變得不可能,因為我的大部分 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
.
推薦答案
好的,我已經通過繼承 UIScrollView
并覆蓋 touchesShouldCancelInContentView
Ok I've solved this by subclassing UIScrollView
and overriding touchesShouldCancelInContentView
現在我的 UIButton
被正確標記為 99 高亮并且我的滾動視圖正在滾動!
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;
}
這篇關于UIScrollView 中的 UIButton 觸摸延遲的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!