繁体   English   中英

防止触摸从 UIImageView 转移到超级视图

[英]Prevent touch transfer to superview from UIImageView

我有一个自定义的垂直范围滑块,并使用 touchBegan、touchMoved 和 touchEnded 处理头部的运动。 当我尝试滑动头部时,它会滑动一点,然后取消触摸并在 iOS 13 上开始交互式关闭转换。我想防止在滑动时将触摸转移到超级视图。 我们如何才能做到这一点。

提前致谢。

尝试将另一个手势识别器用于带有另一个选择器的视图

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tappedOnBubble)];
    [self.bubbleView addGestureRecognizer:tap];

UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tappedOnMainView)];
   [self.view addGestureRecognizer:tap2];


-(void)tappedOnMainView
{
    NSLog(@"touched on main View");
    [self.vwToShow setHidden:NO];
}
-(void)tappedOnView
{
    NSLog(@"tapped on slider");
    [self.vwToShow setHidden:YES];
}

UIView 继承自 UIResponder,基本的触摸事件由触发触摸开始事件的视图检测。 您在主视图中添加的子视图也响应触摸开始方法。这是非常基本的。 您还添加了一个带有点击手势识别器的选择器方法。

如果您仍然想使用 touchBegan ,我认为您应该这样做:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event 
{
    if(theTouchLocation is inside your bubble)
    {
        do something with the touch
    }
    else
    {
        //send the touch to the next view in the hierarchy ( your large view )
       [super touchesBegan:touches withEvent:event];
       [[self nextResponder] touchesBegan:touches withEvent:event];
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM