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

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

问题描述

我有几个 UIButton s,我在主区域点击时用来设置当前操作。我也想允许用户从按钮直接拖动到主区域并采取相同的动作;基本上,当触摸UIButtons时,touchesBegan和touchesMoved应该传递到主视图,而且应该发送按钮按下动作。



现在,我有触摸改变控制。拖动退出调用内部触摸区域设置控件,然后调用touches开始部分开始主区触摸操作。



但是,此时, touchesMoved和touchesEnded显然没有被调用,因为触摸起源于UIButton。



有一种方法可以忽略触摸,所以他们被传递给主

解决方案

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



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



Apple建议使用类似的方法(基于触摸的类型):



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



不是处理触摸事件


$ b p>

  #import< Foundation / Foundation.h> 

@interface MyButton:UIButton {

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

@end

MyButton.m / p>

  #importMyButton.h

@implementation MyButton

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


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.

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.

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?

解决方案

In the documentation, look for Responder Objects and the Responder Chain

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 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.

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\n");
    [self.nextResponder touchesBegan:touches withEvent:event]; 
}
@end

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

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