【发布时间】:2018-02-05 15:46:16
【问题描述】:
结构:
UIView
基础视图
自动布局
- 中心 X
- Y 中心
- 与 SafeView 等宽
- 与 SafeView 等高
UIView
InnerView(BaseView 的子视图)
自动布局
- 领先
- 尾随
- 顶部
- 底部(创建名为“bottomLayoutConstraint”的 IBOutLet)
- (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;
}
为什么出现键盘时Keyboard 和InnerView 之间有间隙?
编辑:
应用 Aleksander Maj 的解决方案后,差距缩小到 5px
编辑:
这是我的视图层次截图
【问题讨论】:
标签: ios objective-c uiview autolayout