Structure:
UIView
BaseView
AutoLayout
- Center X
- Center Y
- Equal Width to SafeView
- Equal Height to SafeView
UIView
InnerView (SubView of BaseView)
AutoLayout
- Leading
- Trailing
- Top
- Bottom (Create the IBOutLet named "bottomLayoutConstraint")
- (void)keyBoardWillShow:(NSNotification *)notification {
NSDictionary *info = notification.userInfo;
NSValue *value = info[UIKeyboardFrameEndUserInfoKey];
CGRect rawFrame = [value CGRectValue];
CGRect keyboardFrame = [self.view convertRect:rawFrame fromView:nil];
self.bottomLayoutConstraint.constant = CGRectGetHeight(keyboardFrame);
[self.view layoutIfNeeded];
}
- (void)keyBoardWillHide:(NSNotification *)notification {
self.bottomLayoutConstraint.constant = 0.0;
}
Why there is a gap between Keyboard
and the InnerView
when keyboard appears?
Edit:
After applying Aleksander Maj's solution the gap reduced to 5px
Edit:
Here is my View hierarchy screenshot