有没有办法在 iPhone 上传递触摸? [英] Is there a way to pass touches through on the iPhone?

查看:31
本文介绍了有没有办法在 iPhone 上传递触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 UIButton 用于在主区域中点击时设置当前操作.我还希望允许用户从按钮直接拖动到主区域并执行相同的操作;本质上,touchesBegan 和 touchesMoved 应该在触摸 UIButtons 时传递给主视图,但也应该发送按钮按下动作.

I have several UIButtons which I use to set the current action when tapping in the main area. I would also like to allow the user to drag from the button directly into the main area and take the same action; essentially, the touchesBegan and touchesMoved should be passed on to the main view when touching the UIButtons, but also should send the button press action.

现在,我在里面修改了控件.拖动退出调用touch up inside部分设置控件,然后调用touches begin部分开始主区域触摸操作.

Right now, I have the touch up inside changing the control. The drag exit calls the touch up inside section to set the control, then calls the touches began section to start the main area touching operation.

然而,在这一点上,touchesMoved 和 touchesEnded 显然没有被调用,因为触摸起源于 UIButton.

However, at this point, the touchesMoved and touchesEnded are obviously not being called, because the touches originated on the UIButton.

有没有办法半忽略触摸,使它们传递到主区域,但也允许我先设置控件?

Is there a way to half-ignore the touches so they're passed to the main area, but also allow me to set the control first?

推荐答案

在文档中,查找 响应者对象和响应者链

您可以通过将触摸转发到响应者链来共享"对象之间的触摸.你的 UIButton 有一个接收 UITouch 事件的响应者/控制器,我的猜测是,一旦它对它返回的消息进行了解释 - 触摸已被处理和处理.

You can "share" touches between objects by forwarding the touch up the responder chain. Your UIButton has a responder/controller that receives the UITouch events, my guess is that once it has preformed its interpretation of the message it returns - the touch has been handled and disposed of.

Apple 建议如下(当然基于触摸类型):

Apple suggests something like this (based on the type of touch of course):

[self.nextResponder touchesBegan:touches withEvent:event];

而不是处理它传递的触摸事件.

Rather than disposing of the touch event it is passed on.

子类 UIButton:

Sub classed UIButton:

MyButton.h

#import <Foundation/Foundation.h>

@interface MyButton : UIButton {

}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event ;

@end

MyButton.m

#import "MyButton.h"

@implementation MyButton

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
    printf("MyButton touch Began
");
    [self.nextResponder touchesBegan:touches withEvent:event]; 
}
@end

这篇关于有没有办法在 iPhone 上传递触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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