iOS手势穿过父视图,父视图上的子视图如何也响应
程序员文章站
2022-03-12 07:51:55
今天有个同事遇到一个问题。在Scroll View上改了一层view。view上有个按钮,他想手势穿过view去滑动Scroll View,但是又想view的上的按钮响应事件。如图:其实很简单:重写test的hitTest方法就好了。如果为父视图响应则向下传递,不然子视图按钮继续响应//// test.swift// test//// Created by quanhao huang on 2020/8/21.// Copyright © 2020 hqh. All rights...
今天有个同事遇到一个问题。在Scroll View上改了一层view。view上有个按钮,他想手势穿过view去滑动Scroll View,但是又想view的上的按钮响应事件。
如图:
其实很简单:
重写test的hitTest方法就好了。如果为父视图响应则向下传递,不然子视图按钮继续响应
// // test.swift // test // // Created by quanhao huang on 2020/8/21. // Copyright © 2020 hqh. All rights reserved. // import UIKit class test: UIView { /*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/ override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { let hitView = super.hitTest(point, with: event) if (hitView == self) { return nil }else { return hitView } } }
(这其实就是一个很简单的响应者链问题)
Demo-手势穿过父视图不影响子视图
本文地址:https://blog.csdn.net/quanhaoH/article/details/108145362
上一篇: Masonry