综合知识iOS单选难度 3真题改编 · 2024
15. 当下面TestView视图以宽200高200正常显示后,下面描述正确的是()
class TestView: UIView {
lazy var controlView: UIControl = {
let v = UIControl(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
v.addTarget(self, action: #selector(clickView(view:)), for: UIControl.Event.touchUpInside)
return v
}()
override init(frame: CGRect){
super.init(frame: frame)
self.addSubview(controlView)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc func clickView(view: UIControl){
print("i am control")
}
public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let stationPoint = self.controlView.convert(point, from: self)
if !self.controlView.bounds.contains(stationPoint){
return self.controlView
}
return self
}
}
练习本题 ›