前提・実現したいこと
Swift3にて画像をドラッグで移動させることができる動作を検討しています。
動作としては、UIImageViewにIDを割り当て
どのViewがタッチされたか判断し、CGPointで座標取得とさせています。
ここで、id:1とid:2を同時に移動させたい時に
どのようなコードを書いていいかというところで躓きました。
ご教授願います。
発生している問題・エラーメッセージ
該当のソースコード
swift3
1//tagが1の時の動作 2class ViewController: UIViewController { 3 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 4 if let touch = touches.first { 5 if let touchedView = touch.view { 6 if touchedView.tag == 1 { 7 gapX = touch.location(in: view).x - touchedView.center.x 8 gapY = touch.location(in: view).y - touchedView.center.y 9 touchedView.center = CGPoint(x: touch.location(in: view).x - gapX, y: touch.location(in: view).y - gapY) 10 }} 11 override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { 12 if let touch = touches.first { 13 if let touchedView = touch.view { 14 if touchedView.tag == 1 { 15 touchedView.center = CGPoint(x: touch.location(in: view).x - gapX, y: 403) 16 }}} 17 override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 18 gapX = 0.0 19 gapY = 0.0 20 }
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
idってなんですか?