I have a problem with Keyboard Extension on iOS (real) device during recoding or phone call (iOS Simulator doesn't have red status bar). Because of the status bar increases 20 points, the custom keyboard also moves 20 points in Y-axis and decreases its height
to 196 points (it should be 216 points). However, when I print the view.frame
, it shows {{0.0, 0.0}, {320.0, 196.0}}.
Here is the screenshot.
If I use storyboard instead of programmatically adding views, it works fine. First I thought it's because of topLayoutGuide.length
, but it shows 0.0 in the debug area.
I has tried to find solution or any topics related to this problem but it seems like me alone facing it. :(
A workaround that works to me:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
if (CGRectGetMinY(self.view.superview.frame) > 0.f) {
CGRect frame = self.view.superview.frame;
frame.origin.y = 0.f;
[self.view.superview setFrame:frame];
}
}
Basically, we're looking for superview's frame and I "adjust" it if it gets shifted.
Edit:
As TomSawyer mentioned, there is an issue with the previous solution. This one should solve them both.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGRect frame = self.view.superview.frame;
CGFloat dy = CGRectGetMinY(frame);
if (dy > 0.f) {
frame.origin.y = 0.f;
frame.size.height += dy;
[self.view.superview setFrame:frame];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With