在实例化时从按下状态开始 UIPanGesture 事件 [英] Begin UIPanGesture Event From A Pressed State At Time Of Instantiation

查看:18
本文介绍了在实例化时从按下状态开始 UIPanGesture 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在实例化对象时手指已经被按下,有没有办法开始 UIPanGestureEvent?

Is there a way to begin a UIPanGestureEvent if the finger is already pressed at the time the object is instantiated?

我有一种情况,当用户在屏幕上按住他们的发现时,我会在他们的手指下创建一个 UIView.

I have a situation where when a user holds their find on a screen I create a UIView under their finger.

我希望他们能够拖动它,因此我在 UIView 中放置了一个 UIPanGestureRecognizer.

I want them to be able to drag that around and as such I have put a UIPanGestureRecognizer inside the UIView.

问题是我需要取下手指并将其放回以触发 UIPanGestureRecognizer 启动.我需要它从已经按下的状态开始.

Problem is I need to take my finger off and put it back to trigger the UIPanGestureRecognizer to start up. I need it to start from an already pressed state.

您知道如何从已经按下的状态激活 UIPanGesture,即我可以获取在实例化时已经处于活动状态的触摸事件并将其传递吗?

Do you know how I can activate a UIPanGesture from an already pressed state i.e. can I get the touch event thats already active at the time of instantiation and pass it along?

推荐答案

您可以做到,但是 UIPanGestureRecognizer 需要已经存在于您创建的视图后面(然后您将必须在此基础上调整您的计算;不难).

You can do it, but the UIPanGestureRecognizer will need to exist already on the view behind the view you create (and you will then have to adjust your calculations based on this; not difficult).

原因是,在您描述的情况下,触摸不属于您创建的 UIView - 它属于其背后的 UIView,即用户最初触摸的那个.鉴于 iOS 触摸交付的性质,您无法轻易改变这一点.所以让那个视图,实际的原始触摸视图,来做这个触摸的处理会更简单.

The reason is that, under the circumstances you describe, the touch does not belong to the UIView you create - it belongs to the UIView behind it, the one that the user was originally touching. And given the nature of iOS touch delivery, you can't readily change that. So it will be simpler to let that view, the actual original touch view, do the processing of this touch.

这篇关于在实例化时从按下状态开始 UIPanGesture 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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