質問編集履歴
3
日本語の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -302,7 +302,7 @@
|
|
302
302
|
|
303
303
|
![イメージ説明](8381593bddc799c8d078d4d20d3e3169.png)
|
304
304
|
|
305
|
-
以下は、回答者様のご指摘により
|
305
|
+
以下は、回答者様のご指摘により変更したことを書きました。書き方や各場所がまだ理解できておらず、まだ解決していない状態です。
|
306
306
|
|
307
307
|
```
|
308
308
|
|
2
日本語の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -324,6 +324,8 @@
|
|
324
324
|
|
325
325
|
```
|
326
326
|
|
327
|
+
を用いて各Touchesのメソッドの中身を変えました。
|
328
|
+
|
327
329
|
```
|
328
330
|
|
329
331
|
/*
|
1
回答者様のご指摘により修正したコードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -301,3 +301,173 @@
|
|
301
301
|
![イメージ説明](4fd2ea51dff2b3a51e4f6b5aac280e98.png)
|
302
302
|
|
303
303
|
![イメージ説明](8381593bddc799c8d078d4d20d3e3169.png)
|
304
|
+
|
305
|
+
以下は、回答者様のご指摘により修正したコードが下記になります。書き方か書く場所がおかしいのかうまくいきません。
|
306
|
+
|
307
|
+
```
|
308
|
+
|
309
|
+
labelT.isUserInteractionEnabled = true
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
と
|
314
|
+
|
315
|
+
```
|
316
|
+
|
317
|
+
if let labelT = touches.first?.view as? UILabel {
|
318
|
+
|
319
|
+
//labelに対してあんなことや、こんなことを‥
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
```
|
326
|
+
|
327
|
+
```
|
328
|
+
|
329
|
+
/*
|
330
|
+
|
331
|
+
タッチを感知した際に呼ばれるメソッド.
|
332
|
+
|
333
|
+
*/
|
334
|
+
|
335
|
+
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
336
|
+
|
337
|
+
//print("touchesBegan")
|
338
|
+
|
339
|
+
print("touchesBeganが呼ばれました")
|
340
|
+
|
341
|
+
// Labelアニメーション.
|
342
|
+
|
343
|
+
UIView.animate(withDuration: 0.06,
|
344
|
+
|
345
|
+
// アニメーション中の処理.
|
346
|
+
|
347
|
+
animations: { () -> Void in
|
348
|
+
|
349
|
+
if let labelT = touches.first?.view as? UILabel {
|
350
|
+
|
351
|
+
labelT.isUserInteractionEnabled = true
|
352
|
+
|
353
|
+
labelT.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
|
354
|
+
|
355
|
+
//labelに対してあんなことや、こんなことを‥
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
})
|
360
|
+
|
361
|
+
{ (Bool) -> Void in
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
/*
|
370
|
+
|
371
|
+
ドラッグを感知した際に呼ばれるメソッド.
|
372
|
+
|
373
|
+
(ドラッグ中何度も呼ばれる)
|
374
|
+
|
375
|
+
*/
|
376
|
+
|
377
|
+
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
print("touchesMovedが呼ばれました")
|
382
|
+
|
383
|
+
//label.isUserInteractionEnabled = true
|
384
|
+
|
385
|
+
// タッチイベントを取得.
|
386
|
+
|
387
|
+
let aTouch: UITouch = touches.first!
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
// 移動した先の座標を取得.
|
392
|
+
|
393
|
+
if let labelT = touches.first?.view as? UILabel {
|
394
|
+
|
395
|
+
labelT.isUserInteractionEnabled = true
|
396
|
+
|
397
|
+
let location = aTouch.location(in: labelT/*self.view*/)
|
398
|
+
|
399
|
+
let prevLocation = aTouch.previousLocation(in: labelT/*self.view*/)
|
400
|
+
|
401
|
+
var myFrame: CGRect = labelT/*self.view*/.frame
|
402
|
+
|
403
|
+
let deltaX: CGFloat = location.x - prevLocation.x
|
404
|
+
|
405
|
+
let deltaY: CGFloat = location.y - prevLocation.y
|
406
|
+
|
407
|
+
myFrame.origin.x += deltaX
|
408
|
+
|
409
|
+
myFrame.origin.y += deltaY
|
410
|
+
|
411
|
+
Finallocation1 = myFrame.origin.x
|
412
|
+
|
413
|
+
Finallocation2 = myFrame.origin.y
|
414
|
+
|
415
|
+
labelT/*self.view*/.frame = myFrame
|
416
|
+
|
417
|
+
//labelに対してあんなことや、こんなことを‥
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
/*
|
426
|
+
|
427
|
+
指が離れたことを感知した際に呼ばれるメソッド.
|
428
|
+
|
429
|
+
*/
|
430
|
+
|
431
|
+
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
print("touchesEndedが呼ばれました")
|
436
|
+
|
437
|
+
//label.isUserInteractionEnabled = true
|
438
|
+
|
439
|
+
// Labelアニメーション.
|
440
|
+
|
441
|
+
UIView.animate(withDuration: 0.1,
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
// アニメーション中の処理.
|
446
|
+
|
447
|
+
animations: { () -> Void in
|
448
|
+
|
449
|
+
if let labelT = touches.first?.view as? UILabel {
|
450
|
+
|
451
|
+
labelT.isUserInteractionEnabled = true
|
452
|
+
|
453
|
+
labelT.transform = CGAffineTransform(scaleX: 0.4, y: 0.4)
|
454
|
+
|
455
|
+
labelT.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
|
456
|
+
|
457
|
+
//labelに対してあんなことや、こんなことを‥
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
})
|
462
|
+
|
463
|
+
{ (Bool) -> Void in
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
print("移動先の座標は、x=(Finallocation1)、y=(Finallocation2)です")
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
}
|
472
|
+
|
473
|
+
```
|