Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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
重叠iOS视图传输触摸时间的问题_Ios_Objective C - Fatal编程技术网

重叠iOS视图传输触摸时间的问题

重叠iOS视图传输触摸时间的问题,ios,objective-c,Ios,Objective C,我创建如下视图: 我创建了两个类(RedView、GreenView),它们是UIView类的子类,并重写了TouchMoved:withEvent函数。代码如下: 在RedView中: -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ NSLog(@"moved in red");} -(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{ NSLog(@“以

我创建如下视图:

我创建了两个类(RedView、GreenView),它们是UIView类的子类,并重写了TouchMoved:withEvent函数。代码如下:

在RedView中:

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

NSLog(@"moved in red");}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
NSLog(@“以红色移动”);}
在GreenView中:

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

NSLog(@"moved in green");}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
NSLog(@“以绿色移动”);}

然后,我按照上面的界面所示进行了创建,但是当我在空白处滑动时,发现了rootViewController、redView、greenView三视图touchMoved:event触发器方法。为什么?我不触摸redView或greenView,我只是在rootViewController的空白处滑动,但为什么两个子视图方法是响应?希望有任何答案……

我认为您需要实现
触摸ForView:

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    if ([event touchesForView:self].count > 0) {
        NSLog(@"moved in red");
    }
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
如果([event touchesForView:self].count>0){
NSLog(@“以红色移动”);
}
}
苹果的触摸事件流文档解释了更多: