質問編集履歴
2
SS追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -400,22 +400,8 @@
|
|
400
400
|
|
401
401
|
])
|
402
402
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
403
|
}
|
408
404
|
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
405
|
|
420
406
|
|
421
407
|
}
|
@@ -425,3 +411,9 @@
|
|
425
411
|
|
426
412
|
|
427
413
|
```
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
![イメージ説明](58b3f2987ffa67b6f6b1346ee2d48da9.png)
|
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -23,3 +23,405 @@
|
|
23
23
|
|
24
24
|
|
25
25
|
何卒ご教授のほどよろしくお願いします。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
※追記
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
ソースコードを追記します。
|
36
|
+
|
37
|
+
完成イメージとしては、SNSのコメント投稿画面のイメージです。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```Swift
|
44
|
+
|
45
|
+
class ViewController:UIViewController,UITextViewDelegate,UITableViewDelegate, UITableViewDataSource{
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
var commentTableView = UITableView(frame: CGRectZero, style: .Grouped)
|
50
|
+
|
51
|
+
//コメント全体のContainer
|
52
|
+
|
53
|
+
var commentAreaContainer = UIView()
|
54
|
+
|
55
|
+
//入力欄
|
56
|
+
|
57
|
+
var commentInput = UITextView()
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
override func viewDidLoad() {
|
64
|
+
|
65
|
+
super.viewDidLoad()
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
commentTableView = UITableView()
|
70
|
+
|
71
|
+
commentTableView.translatesAutoresizingMaskIntoConstraints = false
|
72
|
+
|
73
|
+
self.view.addSubview(commentTableView)
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
commentAreaContainer.translatesAutoresizingMaskIntoConstraints = false
|
78
|
+
|
79
|
+
self.view.addSubview(commentAreaContainer)
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
commentInput.font = UIFont(name: "Helvetica Neue", size: 13.5)
|
84
|
+
|
85
|
+
commentInput.contentInset = UIEdgeInsetsMake(5,0,0,0)
|
86
|
+
|
87
|
+
commentInput.layoutManager.allowsNonContiguousLayout = false
|
88
|
+
|
89
|
+
commentInput.layer.cornerRadius = 2.0
|
90
|
+
|
91
|
+
commentInput.autoresizesSubviews = true
|
92
|
+
|
93
|
+
commentInput.translatesAutoresizingMaskIntoConstraints = false
|
94
|
+
|
95
|
+
commentInput.delegate = self
|
96
|
+
|
97
|
+
commentAreaContainer.addSubview(commentInput)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
//Autolayoutを適用
|
102
|
+
|
103
|
+
setupConstaraints()
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
//input欄の高さが80まではinputの高さをtextに合わせて伸ばす
|
110
|
+
|
111
|
+
func textViewDidChange(textView: UITextView) {
|
112
|
+
|
113
|
+
let maxHeight: CGFloat = 80.0
|
114
|
+
|
115
|
+
if commentInput.frame.size.height < maxHeight {
|
116
|
+
|
117
|
+
let size: CGSize = commentInput.sizeThatFits(commentInput.frame.size)
|
118
|
+
|
119
|
+
//input欄の高さを合わせる
|
120
|
+
|
121
|
+
commentInput.frame.size.height = size.height
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
|
130
|
+
|
131
|
+
textView.scrollRangeToVisible(textView.selectedRange)
|
132
|
+
|
133
|
+
return true
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
func setUpConstraints(){
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
self.view.addConstraints([
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
NSLayoutConstraint(
|
148
|
+
|
149
|
+
item: self.commentTableView,
|
150
|
+
|
151
|
+
attribute: .Top,
|
152
|
+
|
153
|
+
relatedBy: .Equal,
|
154
|
+
|
155
|
+
toItem: self.view,
|
156
|
+
|
157
|
+
attribute: .Top,
|
158
|
+
|
159
|
+
multiplier: 1.0,
|
160
|
+
|
161
|
+
constant: 0
|
162
|
+
|
163
|
+
),
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
NSLayoutConstraint(
|
168
|
+
|
169
|
+
item: self.commentTableView,
|
170
|
+
|
171
|
+
attribute: .Right,
|
172
|
+
|
173
|
+
relatedBy: .Equal,
|
174
|
+
|
175
|
+
toItem: self.view,
|
176
|
+
|
177
|
+
attribute: .Right,
|
178
|
+
|
179
|
+
multiplier: 1.0,
|
180
|
+
|
181
|
+
constant: 0
|
182
|
+
|
183
|
+
),
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
NSLayoutConstraint(
|
188
|
+
|
189
|
+
item: self.commentTableView,
|
190
|
+
|
191
|
+
attribute: .Left,
|
192
|
+
|
193
|
+
relatedBy: .Equal,
|
194
|
+
|
195
|
+
toItem: self.view,
|
196
|
+
|
197
|
+
attribute: .Left,
|
198
|
+
|
199
|
+
multiplier: 1.0,
|
200
|
+
|
201
|
+
constant: 0
|
202
|
+
|
203
|
+
),
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
NSLayoutConstraint(
|
208
|
+
|
209
|
+
item: self.commentTableView,
|
210
|
+
|
211
|
+
attribute: .Bottom,
|
212
|
+
|
213
|
+
relatedBy: .Equal,
|
214
|
+
|
215
|
+
toItem: self.commentAreaContainer,
|
216
|
+
|
217
|
+
attribute: .Bottom,
|
218
|
+
|
219
|
+
multiplier: 1.0,
|
220
|
+
|
221
|
+
constant: -40
|
222
|
+
|
223
|
+
)
|
224
|
+
|
225
|
+
])
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
self.view.addConstraints([
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
NSLayoutConstraint(
|
236
|
+
|
237
|
+
item: self.commentAreaContainer,
|
238
|
+
|
239
|
+
attribute: .Left,
|
240
|
+
|
241
|
+
relatedBy: .Equal,
|
242
|
+
|
243
|
+
toItem: self.view,
|
244
|
+
|
245
|
+
attribute: .Left,
|
246
|
+
|
247
|
+
multiplier: 1.0,
|
248
|
+
|
249
|
+
constant: 0
|
250
|
+
|
251
|
+
),
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
NSLayoutConstraint(
|
256
|
+
|
257
|
+
item: self.commentAreaContainer,
|
258
|
+
|
259
|
+
attribute: .Right,
|
260
|
+
|
261
|
+
relatedBy: .Equal,
|
262
|
+
|
263
|
+
toItem: self.view,
|
264
|
+
|
265
|
+
attribute: .Right,
|
266
|
+
|
267
|
+
multiplier: 1.0,
|
268
|
+
|
269
|
+
constant: 0
|
270
|
+
|
271
|
+
),
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
NSLayoutConstraint(
|
276
|
+
|
277
|
+
item: self.commentAreaContainer,
|
278
|
+
|
279
|
+
attribute: .Bottom,
|
280
|
+
|
281
|
+
relatedBy: .Equal,
|
282
|
+
|
283
|
+
toItem: self.view,
|
284
|
+
|
285
|
+
attribute: .Bottom,
|
286
|
+
|
287
|
+
multiplier: 1.0,
|
288
|
+
|
289
|
+
constant: 0
|
290
|
+
|
291
|
+
)
|
292
|
+
|
293
|
+
])
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
self.view.addConstraints([
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
NSLayoutConstraint(
|
302
|
+
|
303
|
+
item: self.commentInput,
|
304
|
+
|
305
|
+
attribute: .Top,
|
306
|
+
|
307
|
+
relatedBy: .Equal,
|
308
|
+
|
309
|
+
toItem: self.commentAreaContainer,
|
310
|
+
|
311
|
+
attribute: .Top,
|
312
|
+
|
313
|
+
multiplier: 1.0,
|
314
|
+
|
315
|
+
constant: 5
|
316
|
+
|
317
|
+
),
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
NSLayoutConstraint(
|
322
|
+
|
323
|
+
item: self.commentInput,
|
324
|
+
|
325
|
+
attribute: .Bottom,
|
326
|
+
|
327
|
+
relatedBy: .Equal,
|
328
|
+
|
329
|
+
toItem: self.commentAreaContainer,
|
330
|
+
|
331
|
+
attribute: .Bottom,
|
332
|
+
|
333
|
+
multiplier: 1.0,
|
334
|
+
|
335
|
+
constant: -5
|
336
|
+
|
337
|
+
),
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
NSLayoutConstraint(
|
342
|
+
|
343
|
+
item: self.commentInput,
|
344
|
+
|
345
|
+
attribute: .Left,
|
346
|
+
|
347
|
+
relatedBy: .Equal,
|
348
|
+
|
349
|
+
toItem: self.commentAreaContainer,
|
350
|
+
|
351
|
+
attribute: .Left,
|
352
|
+
|
353
|
+
multiplier: 1.0,
|
354
|
+
|
355
|
+
constant: 6
|
356
|
+
|
357
|
+
),
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
NSLayoutConstraint(
|
362
|
+
|
363
|
+
item: self.commentInput,
|
364
|
+
|
365
|
+
attribute: .Right,
|
366
|
+
|
367
|
+
relatedBy: .Equal,
|
368
|
+
|
369
|
+
toItem: self.commentAreaContainer,
|
370
|
+
|
371
|
+
attribute: .Right,
|
372
|
+
|
373
|
+
multiplier: 1.0,
|
374
|
+
|
375
|
+
constant: -6
|
376
|
+
|
377
|
+
),
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
NSLayoutConstraint(
|
382
|
+
|
383
|
+
item: self.commentInput,
|
384
|
+
|
385
|
+
attribute: .Height,
|
386
|
+
|
387
|
+
relatedBy: .Equal,
|
388
|
+
|
389
|
+
toItem: nil,
|
390
|
+
|
391
|
+
attribute: .Height,
|
392
|
+
|
393
|
+
multiplier: 1.0,
|
394
|
+
|
395
|
+
constant: 32
|
396
|
+
|
397
|
+
)
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
])
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
}
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
```
|