話不多說(shuō),上代碼:
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
// 得到不處理的情況下,相應(yīng)點(diǎn)擊的view結(jié)果,目的是不影響其它的點(diǎn)擊
let result = super.hitTest(point, with: event)
// 得到點(diǎn)相對(duì)于button的坐標(biāo)
let testBtnPoint = self.popView.convert(point, from: self)
// 如果坐標(biāo)在button內(nèi),返回這個(gè)button,就會(huì)相應(yīng)button的事件
if self.popView.point(inside: testBtnPoint, with: event) {
return self.popView;
}
// 返回super的響應(yīng)點(diǎn)擊的view
return result
}