Switf3.0
UIImageViewをタップされたことを検出し、何か処理をさせたい場合・・・
次のようにすると良い。
class SubmitViewController: UIViewController {
// ImageViewと接続
@IBOutlet weak var submitImage: UIImageView!
// imageViewにタグ付け
override func viewDidLoad() {
super.viewDidLoad()
submitImage.isUserInteractionEnabled = true
submitImage.tag = tagSubmitImage
}
// タッチイベントの検出
override func touchesEnded(_ touches: Set, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
for touch: UITouch in touches {
let tag = touch.view!.tag
switch tag {
case tagSubmitImage:
print("tapped")
default:
break
}
}
}
}
参考:
http://qiita.com/k-yamada@github/items/79bb31cff50dc9fca321
スポンサーリンク
スポンサーリンク