【发布时间】:2016-04-23 19:27:57
【问题描述】:
知道如何让 inputAccessoryView 锚定到标签栏而不是屏幕底部吗?
我创建了一个 UIViewController 并覆盖了以下方法:
-(BOOL)canBecomeFirstResponder {
return YES;
}
-(UIView *)inputAccessoryView {
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
self.keyboardInputAccessoryView =[[BRKeyboardInputBarView alloc] initWithFrame:frame leftButtonTitle:@"Left" andRightButtonTitle:@"Send"];
[self.keyboardInputAccessoryView setDelegate:self];
[self.keyboardInputAccessoryView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.keyboardInputAccessoryView removeFromSuperview];
return self.keyboardInputAccessoryView;
}
View controller with inputAccessoryView covering the tab bar
从外观上看,视图控制器将视图添加到窗口而不是当前视图控制器的视图,这可以解释其定位。但是,如果我删除该行:
[self.keyboardInputAccessoryView removeFromSuperview];
点击附件视图的文本视图时发生崩溃:
The view hierarchy is not prepared for the constraint:<NSLayoutConstraint:0x7fa0c2ca5f80 BRKeyboardInputBarView:0x7fa0c2d6fad0.bottom == UIInputSetContainerView:0x7fa0c295a2c0.bottom>
所以我想我要问的是添加键盘附件视图的正确方法是什么,以便它可以很好地使用自动布局并避免崩溃,而且还能将自身锚定到视图而不是窗口?
【问题讨论】:
-
我觉得奇怪的是,当键盘没有打开时,accessoryView 就在那里,因为这不是它的默认行为;输入附件应随键盘消失。我认为您最好跟踪键盘的高度并在调用 firstResponder 时向上移动?类似于 UIKeyboardDidShowNotification 和这个问题的答案:stackoverflow.com/questions/25874975/…
标签: ios objective-c