我對swift非常陌生。我正在爲UIIMageview實現點擊事件的功能。我的代碼如下。UIImageview點擊不起作用
override func viewDidLoad() {
super.viewDidLoad()
initialize()
let logout = UIImage(named: "logout.png")
let location = UIImage(named:"location.png")
let appIcon = UIImage(named: "logo.png")
imgLogout.image = logout
imgLocation.image = location
appicon.image = appIcon
// Do any additional setup after loading the view, typically from a nib.
imgLogout.isUserInteractionEnabled = true
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ProductListController.profileImageHasBeenTapped(gesture:)))
//this is where we add the target, since our method to track the taps is in this class
//we can just type "self", and then put our method name in quotes for the action parameter
//finally, this is where we add the gesture recognizer, so it actually functions correctly
imgLogout.addGestureRecognizer(tapGestureRecognizer)
}
func profileImageHasBeenTapped(gesture: UIGestureRecognizer){
print("Triggered")
}
我的點擊事件沒有被觸發。任何身體都可以幫助我。 任何將不勝感激。
的XCode版本8.3.3
雨燕的版本是3.1
是否有一個特殊的原因,你沒有使用這個按鈕? – Alladinian
我需要那裏的形象。所以我用imageview。什麼是使用imageview的障礙? – Noorul
那麼,不,沒有costraint ...但這就是爲什麼'UIButton'存在 – Alladinian