Reputation: 51
I have created a custom keyboard and it works fine. I set the height constraint to be the same as the default keyboard. The issue is that when the keyboard first launches, it starts off below the keyboard and then positions itself to the correct height.
Does anyone know why this is happening?
I attached two images of the launch as it is launching and after it has launched:
I am hardcoding the view height.
override func viewDidLayoutSubviews() {
if UIScreen.main.bounds.width < UIScreen.main.bounds.height {
if UIScreen.main.bounds.height == 667 ||
UIScreen.main.bounds.height == 812 {
viewHeight.constant = 216
} else {
viewHeight.constant = 226
}
} else if UIScreen.main.bounds.width > UIScreen.main.bounds.height {
if (UIScreen.main.bounds.height == 375 && UIScreen.main.bounds.width == 667) || UIScreen.main.bounds.height == 812 || (UIScreen.main.bounds.height == 414 && UIScreen.main.bounds.width == 736) {
viewHeight.constant = 158
} else {
viewHeight.constant = 168
}
}
}
Upvotes: 0
Views: 207
Reputation: 15082
Hard to tell without seeing your code.
If I understand you correctly:
This could have 2 causes:
1) When setting the height constraint on first launch, the value you set is different than the value you see on subsequent launches. Verify that the value you set for the height constraint on first launch is the same value you set as the value you set on subsequent launches and the value the height constraint effectively has on subsequent launches. You can do that by inspecting the layout and/or logging the height constraint values.
2) When the value you set for the height constraint on first launch is the same value you set on subsequent launches and the same value the constraint effectively has, but it is still displayed different, then it may be a layouting issue. Verify that you set the value of the height constraint in the right place of the layouting process, that you properly inform the layout engine that the value has changed and the layout engine has enough time to render the change without getting interrupted.
General approaches:
Take out complexity until your code gets so simple that you have a better chance of nailing down the issue. For debugging, instead of the nested if
s set the height to a fixed value and see if the layout still changes on every launch.
Try other custom keyboard projects you find online and see if these exhibit a similar behavior, maybe that gives you a hint.
Make sure you understand how iOS auto-layout works and research if necessary. This can be quite a complex topic. The code in your question only tells so much, but for auto-layout, view hierarchy and when/where you influence the layouting process in other parts of your code are important aspects. Without seeing the whole view and code structure, this issue is difficult to analyze.
Simplify your project as much as possible and make a demo available on Github that you can reference here, so other people can reproduce the issue.
Upvotes: 1