teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

日本語の修正

2018/05/26 14:27

投稿

TRON1216.
TRON1216.

スコア37

title CHANGED
File without changes
body CHANGED
@@ -150,7 +150,7 @@
150
150
 
151
151
  ![イメージ説明](4fd2ea51dff2b3a51e4f6b5aac280e98.png)
152
152
  ![イメージ説明](8381593bddc799c8d078d4d20d3e3169.png)
153
- 以下は、回答者様のご指摘により修正したコードが下記になり。書き方か書く場所がおしいのかうまくきません
153
+ 以下は、回答者様のご指摘により変更したことを書きした。書き方や各場所がまだ理解できてらず、まだ解決状態です
154
154
  ```
155
155
  labelT.isUserInteractionEnabled = true
156
156
  ```

2

日本語の修正

2018/05/26 14:27

投稿

TRON1216.
TRON1216.

スコア37

title CHANGED
File without changes
body CHANGED
@@ -161,6 +161,7 @@
161
161
  }
162
162
 
163
163
  ```
164
+ を用いて各Touchesのメソッドの中身を変えました。
164
165
  ```
165
166
  /*
166
167
  タッチを感知した際に呼ばれるメソッド.

1

回答者様のご指摘により修正したコードを追加しました。

2018/05/26 14:24

投稿

TRON1216.
TRON1216.

スコア37

title CHANGED
File without changes
body CHANGED
@@ -149,4 +149,89 @@
149
149
  ```
150
150
 
151
151
  ![イメージ説明](4fd2ea51dff2b3a51e4f6b5aac280e98.png)
152
- ![イメージ説明](8381593bddc799c8d078d4d20d3e3169.png)
152
+ ![イメージ説明](8381593bddc799c8d078d4d20d3e3169.png)
153
+ 以下は、回答者様のご指摘により修正したコードが下記になります。書き方か書く場所がおかしいのかうまくいきません。
154
+ ```
155
+ labelT.isUserInteractionEnabled = true
156
+ ```
157
+
158
+ ```
159
+ if let labelT = touches.first?.view as? UILabel {
160
+ //labelに対してあんなことや、こんなことを‥
161
+ }
162
+
163
+ ```
164
+ ```
165
+ /*
166
+ タッチを感知した際に呼ばれるメソッド.
167
+ */
168
+ override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
169
+ //print("touchesBegan")
170
+ print("touchesBeganが呼ばれました")
171
+ // Labelアニメーション.
172
+ UIView.animate(withDuration: 0.06,
173
+ // アニメーション中の処理.
174
+ animations: { () -> Void in
175
+ if let labelT = touches.first?.view as? UILabel {
176
+ labelT.isUserInteractionEnabled = true
177
+ labelT.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
178
+ //labelに対してあんなことや、こんなことを‥
179
+ }
180
+ })
181
+ { (Bool) -> Void in
182
+ }
183
+ }
184
+
185
+ /*
186
+ ドラッグを感知した際に呼ばれるメソッド.
187
+ (ドラッグ中何度も呼ばれる)
188
+ */
189
+ override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
190
+
191
+ print("touchesMovedが呼ばれました")
192
+ //label.isUserInteractionEnabled = true
193
+ // タッチイベントを取得.
194
+ let aTouch: UITouch = touches.first!
195
+
196
+ // 移動した先の座標を取得.
197
+ if let labelT = touches.first?.view as? UILabel {
198
+ labelT.isUserInteractionEnabled = true
199
+ let location = aTouch.location(in: labelT/*self.view*/)
200
+ let prevLocation = aTouch.previousLocation(in: labelT/*self.view*/)
201
+ var myFrame: CGRect = labelT/*self.view*/.frame
202
+ let deltaX: CGFloat = location.x - prevLocation.x
203
+ let deltaY: CGFloat = location.y - prevLocation.y
204
+ myFrame.origin.x += deltaX
205
+ myFrame.origin.y += deltaY
206
+ Finallocation1 = myFrame.origin.x
207
+ Finallocation2 = myFrame.origin.y
208
+ labelT/*self.view*/.frame = myFrame
209
+ //labelに対してあんなことや、こんなことを‥
210
+ }
211
+ }
212
+
213
+ /*
214
+ 指が離れたことを感知した際に呼ばれるメソッド.
215
+ */
216
+ override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
217
+
218
+ print("touchesEndedが呼ばれました")
219
+ //label.isUserInteractionEnabled = true
220
+ // Labelアニメーション.
221
+ UIView.animate(withDuration: 0.1,
222
+
223
+ // アニメーション中の処理.
224
+ animations: { () -> Void in
225
+ if let labelT = touches.first?.view as? UILabel {
226
+ labelT.isUserInteractionEnabled = true
227
+ labelT.transform = CGAffineTransform(scaleX: 0.4, y: 0.4)
228
+ labelT.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
229
+ //labelに対してあんなことや、こんなことを‥
230
+ }
231
+ })
232
+ { (Bool) -> Void in
233
+ }
234
+ print("移動先の座標は、x=(Finallocation1)、y=(Finallocation2)です")
235
+
236
+ }
237
+ ```