Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何";绕道;Cocoa touch中的touch事件?_Iphone_Cocoa Touch_Touch Event - Fatal编程技术网

Iphone 如何";绕道;Cocoa touch中的touch事件?

Iphone 如何";绕道;Cocoa touch中的touch事件?,iphone,cocoa-touch,touch-event,Iphone,Cocoa Touch,Touch Event,我想在当前窗口上创建一个透明的遮罩视图,它只跟踪触摸事件并将它们传递到下面的可见视图。但是,如果我将userInteractionEnabled=YES设置为此掩码,则会阻止事件,并且不会在下面传递 是否有任何方法可以阻止此视图阻止事件或手动传递下面的事件 谢谢,我最近刚刚为我的一个应用程序做了这个,结果很简单 准备好将UIView子类化: 我将我的掩码视图称为catcher视图,协议的外观如下: @interface CatcherView : UIView { UIView *vi

我想在当前窗口上创建一个透明的遮罩视图,它只跟踪触摸事件并将它们传递到下面的可见视图。但是,如果我将userInteractionEnabled=YES设置为此掩码,则会阻止事件,并且不会在下面传递

是否有任何方法可以阻止此视图阻止事件或手动传递下面的事件


谢谢,

我最近刚刚为我的一个应用程序做了这个,结果很简单

准备好将UIView子类化:

我将我的掩码视图称为catcher视图,协议的外观如下:

@interface CatcherView : UIView {

    UIView *viewBelow;

}

@property(nonatomic,retain)UIView *viewBelow;

@end
这里您只是对UIView进行子类化,并保留对下面视图的引用

在实现上,您需要完全实现至少4种方法,以将触摸传递到视图或以下视图,这些方法的外观如下:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Began");
    [self.viewBelow touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Moved");
    [self.viewBelow touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Ended");

    [self.viewBelow touchesEnded:touches withEvent:event];
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"Touch Cancelled");
    //Not necessary for my app but you just need to forward it to your view bellow.
}
创建视图时,请记住设置一个或多个以下视图;将背景色设置为“清晰”也是非常重要的,因此它可以充当遮罩。看起来是这样的:

    CatcherView *catchView=[[CatcherView alloc] initWithFrame:[self.view bounds]];
    catchView.backgroundColor=[UIColor clearColor];
    catchView.viewBelow=myViewBellow;
    [self.view addSubview:catchView];
希望它能帮助您,如果您需要更多信息,请发表评论。

  • UIKit通过沿响应程序链发送
    -hitTest:withEvent:
    消息来确定事件的目标视图
  • 一旦找到目标,事件将沿响应程序链向上发送,直到找到处理它的响应程序为止(通常是已触及的视图,但不总是)

因此,如果您在适当的高视图中覆盖
-[NSView hitTest:withEvent:][/code>(可能通过使用自定义窗口!),您可以记录所有传入事件,并调用
super
,使其正常工作。

感谢您的回答,但在我的情况下,这似乎不起作用。。。我必须将事件发送到整个窗口,而不是特定视图。我尝试将事件发送到窗口的根视图,但没有成功。