为了账号安全,请及时绑定邮箱和手机立即绑定

iOS-通过视图转发所有触摸

iOS-通过视图转发所有触摸

iOS
白板的微信 2019-12-25 15:32:09
我有一个视图叠加在许多其他视图之上。我只不过是在检测屏幕上的某些触摸而已,但除此之外,我不希望该视图停止其下的其他视图(例如滚动视图)的行为。如何转发所有触摸此叠加视图?它是UIView的子目录。
查看完整描述

3 回答

?
慕虎7371278

TA贡献1802条经验 获得超4个赞

要将触摸从叠加视图传递到其下的视图,请在UIView中实现以下方法:


目标C:


- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {

    NSLog(@"Passing all touches to the next view (if any), in the view stack.");

    return NO;

}

迅速:


override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {

    print("Passing all touches to the next view (if any), in the view stack.")

    return false

}


查看完整回答
反对 回复 2019-12-25
?
长风秋雁

TA贡献1757条经验 获得超7个赞

这是一个旧线程,但是它是在搜索时出现的,因此我想添加2c。我有一个包含子视图的UIView,并且只想拦截击中一个子视图的触摸,所以我修改了PixelCloudSt的答案


-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

{

    for (UIView* subview in self.subviews ) {

        if ( [subview hitTest:[self convertPoint:point toView:subview] withEvent:event] != nil ) {

            return YES;

        }

    }

    return NO;

}


查看完整回答
反对 回复 2019-12-25
  • 3 回答
  • 0 关注
  • 540 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信