Warning: Trying to access array offset on value of type bool in /home/c4323839/public_html/tak-lab.net/wp-content/plugins/only-tweet-like-share-and-google-1/tweet-like-plusone.php on line 258

Warning: Undefined array key 0 in /home/c4323839/public_html/tak-lab.net/wp-content/plugins/only-tweet-like-share-and-google-1/tweet-like-plusone.php on line 245
iOS開発Tips

[Swift] UIImageViewのタップイベント処理を検出する


Warning: Undefined variable $cs1 in /home/c4323839/public_html/tak-lab.net/wp-content/plugins/only-tweet-like-share-and-google-1/tweet-like-plusone.php on line 813

Warning: Undefined variable $cs2 in /home/c4323839/public_html/tak-lab.net/wp-content/plugins/only-tweet-like-share-and-google-1/tweet-like-plusone.php on line 813

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

COMMENT

メールアドレスが公開されることはありません。 が付いている欄は必須項目です