質問編集履歴

4

コードの変更

2019/01/15 13:34

投稿

mimamo
mimamo

スコア44

test CHANGED
File without changes
test CHANGED
@@ -72,13 +72,13 @@
72
72
 
73
73
  let imageWidth = screenWidth * 210 / 148
74
74
 
75
- let rect:CGRect = CGRect(x:0, y:0, width:screenWidth, height:imageWidth)
75
+ let imagerect:CGRect = CGRect(x:0, y:0, width:screenWidth, height:imageWidth)
76
76
 
77
77
 
78
78
 
79
79
  // getimage(ImageView) frame をCGRectで作った矩形に合わせる
80
80
 
81
- getimage.frame = rect;
81
+ getimage.frame = imagerect;
82
82
 
83
83
 
84
84
 

3

コードの変更

2019/01/15 13:34

投稿

mimamo
mimamo

スコア44

test CHANGED
File without changes
test CHANGED
@@ -126,8 +126,88 @@
126
126
 
127
127
 
128
128
 
129
+
130
+
131
+
132
+
133
+ if let touch = touches.first {
134
+
135
+ // タッチしたビューをviewプロパティで取得する
136
+
137
+ if let touchedView = touch.view {
138
+
139
+ // tag1のものを動かす
140
+
141
+ if touchedView.tag == 1 {
142
+
143
+ // gapX,gapYの取得は行わない
144
+
145
+ touchedView.center = CGPoint(x: touch.location(in: view).x - gapX, y: touch.location(in: view).y - gapY)
146
+
147
+
148
+
149
+
150
+
151
+ if touchedView.center.x <= rect.minX{
152
+
153
+ touchedView.center.x = rect.minX
154
+
155
+ }
156
+
157
+ if touchedView.center.x >= rect.maxX{
158
+
159
+ touchedView.center.x = rect.maxX
160
+
161
+ }
162
+
163
+ if touchedView.center.y <= rect.minY{
164
+
165
+ touchedView.center.y = rect.minY
166
+
167
+ }
168
+
169
+ if touchedView.center.y >= rect.maxY{
170
+
171
+ touchedView.center.y = rect.maxY
172
+
173
+ }
174
+
175
+ }
176
+
177
+ }
178
+
129
179
  }
130
180
 
181
+ }
182
+
183
+
184
+
185
+ override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
186
+
187
+
188
+
189
+ // gapXとgapYの初期化
190
+
191
+ gapX = 0.0
192
+
193
+ gapY = 0.0
194
+
195
+ }
196
+
197
+
198
+
199
+ override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
200
+
201
+ // touchesEndedと同じ処理
202
+
203
+ self.touchesEnded(touches, with: event)
204
+
205
+ }
206
+
207
+
208
+
209
+ }
210
+
131
211
 
132
212
 
133
213
 

2

タイトルの変更

2019/01/15 13:26

投稿

mimamo
mimamo

スコア44

test CHANGED
@@ -1 +1 @@
1
- タッチよって作られる矩形の中心位置を常に画面の真ん中に設定したい
1
+ CGRectの中心位置を設定したい
test CHANGED
File without changes

1

タイトル

2019/01/15 05:19

投稿

mimamo
mimamo

スコア44

test CHANGED
@@ -1 +1 @@
1
- 矩形の中心位置を設定したい
1
+ タッチのよって作られる矩形の中心位置を常に画面の真ん中に設定したい
test CHANGED
File without changes