默认情况下,在UIImageView
实例中禁用用户交互。并且当超级视图的用户交互被禁用时,即使您设置了子视图,其子视图也无法接收用户交互button.isUserInteractiOnEnabled= true
因此,添加imageView.isUserInteractiOnEnabled= true
在backgroundImageView
关闭
let backgroundImageView: UIImageView = { let imageView = UIImageView() imageView.isUserInteractiOnEnabled= true imageView.translatesAutoresizingMaskIntoCOnstraints= false imageView.layer.masksToBounds = true return imageView }()