如何将不同的 UIGestureRecognizer 附加到同一 UITextView 的“不同”部分
我想将不同的 UIGestureRecognizer 附加到文本不同部分的同一个 UITextView 上。
例如,“我很棒,你也是”,当用户点击“我很棒”时,应用程序会执行某些操作,而当用户点击“你也是”时,应用程序会执行其他操作。
可以这样做吗? (注意:将它们分成 2 个字符串不是解决方案,因为它可以缠绕)
谢谢!
I want to attach different UIGestureRecognizer(s) to the same UITextView on different parts of the text.
E.g., "I am awesome and you are too", when user taps on "I am awesome" the app would do something and when user taps on "you are too" the app would do something else.
Is it possible to do that? (note: break them into 2 strings is not a solution since it could be wrapped around)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想到了几个解决方案:
如果您使用 UILabels 来显示字符串,则可以在标签上启用用户交互,并向每个标签添加单独的手势识别器。
或者,您可以有一个手势识别器,并在处理手势的方法中找出触摸位置(如果是点击手势识别器,您可以使用
locationInView:
来获取其位置在给定的视图中)。然后,当你确定触摸了什么时,A couple solutions spring to mind:
If you are using UILabels to display the strings, you could enable user interaction on the labels and add seperate gesture recognizers to each label.
Alternately, you could have one gesture recognizer and in the method to handle the gesture, figure out where the touch was (if it is a tap gesture recognizer, you can use
locationInView:
to, well get its location in a given view). Then, when you determine what was touched,