我的应用遇到了一个小问题.
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 触摸延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!