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 触摸延迟
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01