不太了解touchesBegan和touchesEnded [英] Not quite understanding touchesBegan and touchesEnded

查看:48
本文介绍了不太了解touchesBegan和touchesEnded的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了 Apple 的示例 Touches 应用程序,但它没有解决我的问题.在他们的示例应用程序中,当发生触摸事件时,它会尝试将视图保持在发生触摸事件的位置.这使逻辑变得简单.他们只是寻找框架包含触摸位置的视图.

I've looked at Apple's sample touches app, and it doesn't address my issue. In their sample app, when a touch event happens, it tries to keep the view(s) located where the touch event is happening. That makes the logic simple. They simply look for the views whose frames contain the touch location.

这在我的场景中不起作用.这是我的场景.

That doesn't work in my scenario. Here is my scenario.

有一个包含一堆子视图的视图.这个想法是允许用户在他们手势的方向上抛出一个子视图.我希望 touchesBegan 事件找到中心最接近触摸的视图.

There is a view containing a bunch of subviews. The idea is to allow the user to sort of fling one of the subviews in the direction they gesture. I want the touchesBegan event to find the view whose center is closest to the touch.

然后我希望 touchesEnded 事件以由开始和结束事件确定的速度移动同一个视图.速度不一定与手指速度相同,因此我不能像 Apple 在示例应用中所做的那样简单地将视图附加"到触摸位置.

I then want the touchesEnded event to move that same view by a velocity that is determined by the beginning and ending events. The velocity will not necessarily be the same as the finger velocity, so I can't simply "attach" the view to the touch location as Apple has done in the sample app.

我想用触摸对象标记touchesBegan 中标识的视图,并使用它与touchesEnded 事件中的触摸对象进行比较,但这不起作用.touchesBegantouchesEnded 事件的触摸对象不同.

I thought of flagging the view identified in touchesBegan with the touch object, and using it to compare with the touch object in the touchesEnded event, but that's not working. The touch object is not the same for the touchesBegan and touchesEnded events.

那我错过了什么?如何保存要移动的视图和触摸之间的关系?

So what am I missing? How can I save the relationship between the view to be moved and the touch?

推荐答案

实际上,touchesBegantouchesEnded 中的触摸对象是相同的.结果证明这是跟踪接触的方式.

The touch object is, actually, the same in touchesBegan and touchesEnded. That turned out to be the way to track the touches.

这篇关于不太了解touchesBegan和touchesEnded的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆