用手指做一个UIView拖动 [英] Make a UIView draggable with the finger

查看:132
本文介绍了用手指做一个UIView拖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 mainViewController 但是我内部有一个小的 UIView ,当你点击<$ c时会激活$ c> MKAnnotationView 在 MKMapKit 中,所以我需要 UIView 才可以拖放屏幕的任何部分。

I have the mainViewController but I have an small UIView inside that is activated when you tap a MKAnnotationView in the MKMapKit, so I need that UIView to be draggable in any part of the screen.

我的应用程序的示例屏幕截图:

An example screenshot of my app:

圆圈是一个例子,我想我可以拖动小UIView的任何一点。

The circle is an example of point, I suppose I can drag for any point of the "small" UIView.

我尝试使用 UITapGestureRecognizer 但它没有用我的代码不够好,我无法将其拖动,因为它只是点击,而不是点击和移动。

I tried using UITapGestureRecognizer but it didn't worked as my code was not good enough and I could not made it draggable because it's only the tap, not tap and move.

我希望你能帮助我。

推荐答案


  1. 使用 UIPanGestureRecognizer 而不是 UITapGestureRecognizer

  2. 为您的视图设置 userInteractionEnabled = YES

  3. 查看有关手势识别器的精彩教程:触摸。有一个很好的拖动视图的例子。

  1. Use UIPanGestureRecognizer instead of UITapGestureRecognizer
  2. Set userInteractionEnabled = YES for your view
  3. Review this nice tutorial about gesture recognizers: Touches. There is nice example of dragging views.

这篇关于用手指做一个UIView拖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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