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

我有一个视图叠加在许多其他视图之上。我只不过是在检测屏幕上的某些触摸而已,但除此之外,我不希望该视图停止其下的其他视图(例如滚动视图)的行为。如何转发所有触摸此叠加视图?它是UIView的子目录。



白板的微信
浏览 541回答 3
3回答

慕虎7371278

要将触摸从叠加视图传递到其下的视图,请在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}

长风秋雁

这是一个旧线程,但是它是在搜索时出现的,因此我想添加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;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

iOS