为什么当 UIImageView 放置在 UIScrollView 中时,touchesBegan 停止工作?

发布于 2024-10-09 19:05:14 字数 470 浏览 6 评论 0原文

UIView -> UIImageView

我知道我的工作有些正常,因为我可以点击 UIImageView 并在 touchesBegan 方法中看到 NSLog() 语句。

UIView -> UIScrollView -> UIImageView

我将相同的 UIImageView 拖到 UIScrollView 中,当我点击 UIImageView 时,touchesBegan 不再被调用。 (我没有更改任何其他内容。所有相同的连接、方法和代码保持不变。)

为什么 touchesBegan 不再起作用?我该怎么做才能让它再次运行?

UIView -> UIImageView

I know I have things somewhat working ok since I can tap on my UIImageView and see an NSLog() statement in my touchesBegan method.

.

UIView -> UIScrollView -> UIImageView

I drag that same UIImageView into a UIScrollView and touchesBegan no longer gets called when I tap on my UIImageView. (I haven't changed anything else. All the same connections, methods, and code remains unchanged.)

Why does touchesBegan no longer work? And what can I do to get it working again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁许谁一生繁华 2024-10-16 19:05:14

添加 uitapgesture 来获取事件

代码是

  UITapGestureRecognizer *ges11=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Handeltap:)];
  [imagename addGestureRecognizer:ges11];

创建一个名为“Handeltap”的操作,您将在那里被调用。

Add uitapgesture to get event

Code is

  UITapGestureRecognizer *ges11=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Handeltap:)];
  [imagename addGestureRecognizer:ges11];

Create one action name "Handeltap" U will get called there.

番薯 2024-10-16 19:05:14

默认情况下,UIImageView 不处理用户手势。
UIImageView 实例的 userInteractionEnabled 设置为 YES

by default UIImageView don't handle user gestures.
set UIImageView instance's userInteractionEnabled to YES

呆头 2024-10-16 19:05:14

查看 UIScrollView 的文档。

因为滚动视图没有滚动条,所以它必须知道触摸信号是否表示滚动意图或跟踪内容中的子视图的意图。为了做出此确定,它通过启动计时器来临时拦截触地事件,并在计时器启动之前查看触摸手指是否进行任何移动。如果计时器在位置没有显着变化的情况下触发,则滚动视图会将跟踪事件发送到内容视图的触摸子视图。如果用户在计时器结束之前将手指拖动得足够远,则滚动视图将取消子视图中的任何跟踪并自行执行滚动。子类可以重写 touchesShouldBegin:withEvent:inContentView:pagingEnabledtouchesShouldCancelInContentView: 方法(由滚动视图调用)来影响滚动视图处理滚动手势。

我还建议阅读 滚动视图编程指南

Have a look at the documentation for UIScrollView.

Because a scroll view has no scroll bars, it must know whether a touch signals an intent to scroll versus an intent to track a subview in the content. To make this determination, it temporarily intercepts a touch-down event by starting a timer and, before the timer fires, seeing if the touching finger makes any movement. If the timer fires without a significant change in position, the scroll view sends tracking events to the touched subview of the content view. If the user then drags their finger far enough before the timer elapses, the scroll view cancels any tracking in the subview and performs the scrolling itself. Subclasses can override the touchesShouldBegin:withEvent:inContentView:, pagingEnabled, and touchesShouldCancelInContentView: methods (which are called by the scroll view) to affect how the scroll view handles scrolling gestures.

I'd also recommend reading the Scroll View Programming Guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文