【发布时间】:2021-08-28 02:21:06
【问题描述】:
private let myView: UIView = {
let view = UIView()
view.backgroundColor = .color(fromHexString: "EDF1F4")
view.layer.cornerRadius = 15
view.layer.masksToBounds = true
view.layer.borderWidth = 2
view.layer.borderColor = UIColor.color(fromHexString: "FFFFFF").cgColor
// click event
let tap = UITapGestureRecognizer(target: self, action: #selector(myViewTapped))
tap.numberOfTapsRequired = 1
view.isUserInteractionEnabled = true
view.addGestureRecognizer(tap)
return view
}()
如您所见,我添加了背景颜色,因此背景不透明,并且我还添加了isUserInteractionEnabled = true
但这是行不通的。
【问题讨论】: