Skip to content

Commit a2a94e9

Browse files
committed
Update demo with autolayout
1 parent 475f225 commit a2a94e9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Keyboard/KeyboardViewController.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ class KeyboardViewController: UIInputViewController, CustomKeyboardDelegate {
1414
// MARK: - Lifecycle
1515
override func viewDidLoad() {
1616
super.viewDidLoad()
17+
setupKeyboard()
18+
}
19+
20+
private func setupKeyboard() {
1721
customKeyboard = CustomKeyboard()
1822
customKeyboard.delegate = self
23+
customKeyboard.translatesAutoresizingMaskIntoConstraints = false
1924
view.addSubview(customKeyboard)
2025

26+
// Autolayout
27+
customKeyboard.leftAnchor.constraintEqualToAnchor(view.leftAnchor).active = true
28+
customKeyboard.rightAnchor.constraintEqualToAnchor(view.rightAnchor).active = true
29+
customKeyboard.topAnchor.constraintEqualToAnchor(view.topAnchor).active = true
30+
customKeyboard.bottomAnchor.constraintEqualToAnchor(view.bottomAnchor).active = true
31+
2132
// This is how you add extra buttons to layouts for customising CustomKeyboard without even subclass it!
2233
let customButton = KeyboardButton(
2334
type: .Text("🕶"),
@@ -30,11 +41,6 @@ class KeyboardViewController: UIInputViewController, CustomKeyboardDelegate {
3041
buttonIndex: 2)
3142
}
3243

33-
override func viewDidLayoutSubviews() {
34-
super.viewDidLayoutSubviews()
35-
customKeyboard?.frame = view.frame
36-
}
37-
3844
// MARK: CustomKeyboardDelegate
3945
func customKeyboardKeyButtonPressed(customKeyboard: CustomKeyboard, key: String) {
4046
if customKeyboard == self.customKeyboard {

0 commit comments

Comments
 (0)