質問編集履歴
4
コードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -35,10 +35,10 @@
|
|
35
35
|
screenHeight = self.view.bounds.height
|
36
36
|
|
37
37
|
let imageWidth = screenWidth * 210 / 148
|
38
|
-
let
|
38
|
+
let imagerect:CGRect = CGRect(x:0, y:0, width:screenWidth, height:imageWidth)
|
39
39
|
|
40
40
|
// getimage(ImageView) frame をCGRectで作った矩形に合わせる
|
41
|
-
getimage.frame =
|
41
|
+
getimage.frame = imagerect;
|
42
42
|
|
43
43
|
// 画像の中心をスクリーンの中心位置に設定
|
44
44
|
getimage.center = CGPoint(x:screenWidth/2, y:screenHeight/2)
|
3
コードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,9 +62,49 @@
|
|
62
62
|
|
63
63
|
rect.center = CGPoint(x:screenWidth/2, y:screenHeight/2)
|
64
64
|
|
65
|
+
|
66
|
+
|
67
|
+
if let touch = touches.first {
|
68
|
+
// タッチしたビューをviewプロパティで取得する
|
69
|
+
if let touchedView = touch.view {
|
70
|
+
// tag1のものを動かす
|
71
|
+
if touchedView.tag == 1 {
|
72
|
+
// gapX,gapYの取得は行わない
|
73
|
+
touchedView.center = CGPoint(x: touch.location(in: view).x - gapX, y: touch.location(in: view).y - gapY)
|
74
|
+
|
75
|
+
|
76
|
+
if touchedView.center.x <= rect.minX{
|
77
|
+
touchedView.center.x = rect.minX
|
78
|
+
}
|
79
|
+
if touchedView.center.x >= rect.maxX{
|
80
|
+
touchedView.center.x = rect.maxX
|
81
|
+
}
|
82
|
+
if touchedView.center.y <= rect.minY{
|
83
|
+
touchedView.center.y = rect.minY
|
84
|
+
}
|
85
|
+
if touchedView.center.y >= rect.maxY{
|
86
|
+
touchedView.center.y = rect.maxY
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
65
90
|
}
|
91
|
+
}
|
92
|
+
|
93
|
+
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
66
94
|
|
95
|
+
// gapXとgapYの初期化
|
96
|
+
gapX = 0.0
|
97
|
+
gapY = 0.0
|
98
|
+
}
|
99
|
+
|
100
|
+
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
|
101
|
+
// touchesEndedと同じ処理
|
102
|
+
self.touchesEnded(touches, with: event)
|
103
|
+
}
|
67
104
|
|
105
|
+
}
|
106
|
+
|
107
|
+
|
68
108
|
```
|
69
109
|
|
70
110
|
|
2
タイトルの変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
CGRectの中心位置を設定したい
|
body
CHANGED
File without changes
|
1
タイトル
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
矩形の中心位置を設定したい
|
1
|
+
タッチのよって作られる矩形の中心位置を常に画面の真ん中に設定したい
|
body
CHANGED
File without changes
|