是否可以在 iPhone 中重新创建用户手势?
我正在开发一个应用程序,遇到了一个问题,归结为这种情况: 考虑一个具有两个按钮(按钮1,按钮2)和一个文本视图的超级视图,全部作为其子视图。当我单击一个按钮时,我会显示文本视图。当我点击文本视图之外的任何位置但在超级视图中时,我需要关闭文本视图。
我已将 UITapGestureRecognizer 添加到超级视图,它调用方法 tap: 。在 tap: 中,我得到了点击点,如果它位于文本视图之外,我会关闭文本视图并删除 GestureRecognizer。现在,当我点击按钮 2 时,问题就出现了。我需要关闭文本视图并执行按钮 2 的操作。但它输入了 tap: 并且我不想从那里调用按钮 2 的方法。
我想知道的是,在移除手势识别器后是否可以在相同坐标处模拟相同的点击?如果不是,我该如何解决这个问题?
编辑 我已经尝试过:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
但这并不能解决我的问题
I am developing an app and I have encountered a problem that comes down to this scenario:
Consider a superview with two buttons(button1,button2) and a text view, all as its subviews. When I click on one button, I display the text view. When I tap on anywhere outside the textview, but in the super view, I need to dismiss the text view.
I have added a UITapGestureRecognizer to the super view and it calls a method tap:. In tap:, I get the point of the tap and if it is outside the text view, I dismiss the text view and remove the GestureRecognizer. Now the problem occurs when I tap on button 2. I need to dismiss the text view as well as execute the action for button 2. But it enters tap: and I do not wish to call the button 2's method from there.
What I want to know is if it would be possible to emulate the same tap at the same co ordinates after the gesture recognizer is removed? If not what is the way I proceed to solve this issue?
EDIT
I have tried:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
But it does nt solve my problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个简单的方法可以做到这一点。这对我来说工作得很好。请在“UIcontroleventTouchdown”事件中调用您的方法。
There is an easy way for this. This is work fine for me. Please call your method in "UIcontroleventTouchdown" event.
我不知道是否可以在 iPhone 中重新创建用户手势,但您可以使用一种简单的方法来实现您所需要的。您可以使用一个方法,
您可以返回 UIGestureRecognizer 是否应该接收触摸,或者换句话说是否应该执行与手势识别器绑定的方法。如果您返回
NO
,它将把触摸传递给子视图。不要忘记设置手势识别器的
delegate
。并在.h
文件中包含UIGestureRecognizerDelegate
协议您可以检查触摸是否在按钮框架内,然后您可以
返回NO
,否则返回是的
以下是文档 UIGestureRecognizer <一个href="http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIGestureRecognizerDelegate" rel="nofollow">UIGestureRecognizerDelegate< /a>
I don't know about is it possible to recreate User Gestures in iPhone or not but there is an easy way around you can use to achieve what you need. There is a method you can use is
You can return whether the
UIGestureRecognizer
should receive touch or in other words should execute the method bound with gesture recognizer. If you returnNO
it will pass the touch to the subviews.Do not forget to set
delegate
of the gesture recognizer. and includingUIGestureRecognizerDelegate
protocol in.h
fileYou can check if the touch is within the button frame then you can
return NO
elsereturn YES
Here are the docs UIGestureRecognizer UIGestureRecognizerDelegate