ios UIImageView 添加点击事件

433 阅读1分钟
let noDataTalkImg = UIImageView().then { attr in
            attr.image = UIImage(named: "white_home_npc_talk")
            //这个属性要设置 不然没反应
            attr.isUserInteractionEnabled = true
        }
        
noDataTalkImg.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(openAddRecordPage)))

@objc
func openAddRecordPage(){
     print("openAddRecordPage","ccc")
     self.navigationController?.pushViewController(AddCategoryController(), animated: true)
 }