Switf3.0
UIImageViewをタップされたことを検出し、何か処理をさせたい場合・・・
次のようにすると良い。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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
最近のコメント