質問編集履歴
2
キャプチャー追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
![storyboard](48109e2b4810478ee8bc2487fd45be1a.png)
|
2
|
+
|
3
|
+
|
4
|
+
|
1
5
|
// キーボード非表示の時 に下に余白が空いてしまいます。
|
2
6
|
|
3
7
|
[参照リンク](http://qiita.com/ysk_1031/items/3adb1c1bf5678e7e6f98)
|
1
コード変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
fatal error: unexpectedly found nil while unwrapping an Optional valueというエラーが出てしまいます。
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
// キーボード表示の時
|
1
|
+
// キーボード非表示の時 に下に余白が空いてしまいます。
|
6
2
|
|
7
3
|
[参照リンク](http://qiita.com/ysk_1031/items/3adb1c1bf5678e7e6f98)
|
8
4
|
|
@@ -106,46 +102,40 @@
|
|
106
102
|
|
107
103
|
let userInfo = notification.userInfo!
|
108
104
|
|
109
|
-
let keyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as AnyObject).cgRectValue
|
110
|
-
|
111
|
-
let animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as AnyObject).doubleValue
|
112
|
-
|
113
105
|
// キーボードの大きさを取得
|
114
106
|
|
115
|
-
|
107
|
+
let keyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
|
116
|
-
|
108
|
+
|
117
|
-
|
109
|
+
let animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSValue)
|
110
|
+
|
111
|
+
restoreScrollViewSize()
|
112
|
+
|
113
|
+
print("キーボードを表示2")
|
114
|
+
|
115
|
+
let convertedKeyboardFrame = testScrollView.convert(keyboardFrame, from: nil)
|
116
|
+
|
117
|
+
print("キーボードを表示3")
|
118
|
+
|
119
|
+
let offsetY: CGFloat = testTextField.frame.maxY - convertedKeyboardFrame.minY
|
120
|
+
|
121
|
+
if offsetY < 0 { return }
|
122
|
+
|
123
|
+
updateScrollViewSize(moveSize: offsetY, duration: animationDuration as! TimeInterval)
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
// キーボード非表示の時
|
130
|
+
|
131
|
+
func keyboardWillBeHidden(notification: NSNotification) {
|
132
|
+
|
133
|
+
print("キーボードを非表示しました")
|
134
|
+
|
135
|
+
testScrollView.contentOffset.y = 0
|
118
136
|
|
119
137
|
// restoreScrollViewSize()
|
120
138
|
|
121
|
-
// let convertedKeyboardFrame = testScrollView.convert(keyboardScreenEndFrame, from: nil)
|
122
|
-
|
123
|
-
// let offsetY: CGFloat = testTextField.frame.maxY - convertedKeyboardFrame.minY
|
124
|
-
|
125
|
-
restoreScrollViewSize()
|
126
|
-
|
127
|
-
let convertedKeyboardFrame = testScrollView.convert(keyboardFrame!, from: nil)
|
128
|
-
|
129
|
-
let offsetY: CGFloat = testTextField.frame.maxY - convertedKeyboardFrame.minY
|
130
|
-
|
131
|
-
if offsetY < 0 { return }
|
132
|
-
|
133
|
-
updateScrollViewSize(moveSize: offsetY, duration: animationDuration! as TimeInterval)
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
// キーボード非表示の時
|
140
|
-
|
141
|
-
func keyboardWillBeHidden(notification: NSNotification) {
|
142
|
-
|
143
|
-
print("キーボードを非表示しました")
|
144
|
-
|
145
|
-
testScrollView.contentOffset.y = 0
|
146
|
-
|
147
|
-
// restoreScrollViewSize()
|
148
|
-
|
149
139
|
}
|
150
140
|
|
151
141
|
|
@@ -208,6 +198,4 @@
|
|
208
198
|
|
209
199
|
}
|
210
200
|
|
211
|
-
|
212
|
-
|
213
201
|
```
|