UIButton touch is delayed when in UIScrollView(UIScrollView 中的 UIButton 触摸延迟)
问题描述
我的应用遇到了一个小问题.
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 触摸延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIScrollView 中的 UIButton 触摸延迟
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
