重叠iOS视图传输触摸时间的问题
我创建如下视图: 我创建了两个类(RedView、GreenView),它们是UIView类的子类,并重写了TouchMoved:withEvent函数。代码如下: 在RedView中:重叠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(@“以
-(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(@“以红色移动”);
}
}
苹果的触摸事件流文档解释了更多: