简体   繁体   English

InputAccessoryView涵盖了底栏

[英]InputAccessoryView covers the bottom bar

Any idea how to get an inputAccessoryView to anchor to the tab bar rather than the bottom of the screen? 知道如何让inputAccessoryView锚定到标签栏而不是屏幕底部?

I have created a UIViewController and overridden the following methods: 我创建了一个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 使用inputAccessoryView查看控制器,覆盖标签栏

By the looks of it the view controller adds the view to the window rather than the current view controllers view, which would explain its positioning. 通过它的外观,视图控制器将视图添加到窗口而不是当前视图控制器视图,这将解释其定位。 However if I remove the line: 但是,如果我删除该行:

[self.keyboardInputAccessoryView removeFromSuperview];

I get a crash when I tap in the textview of my accessory view: 当我点击附件视图的textview时,我遇到了崩溃:

The view hierarchy is not prepared for the constraint:<NSLayoutConstraint:0x7fa0c2ca5f80 BRKeyboardInputBarView:0x7fa0c2d6fad0.bottom == UIInputSetContainerView:0x7fa0c295a2c0.bottom>

So I guess what I am asking is what is the correct way to add a keyboard accessory view so that it plays nicely with auto layout and avoids the crash, but also anchors itself to the view and not the window? 所以我想我要问的是添加键盘配件视图的正确方法是什么,以便它可以很好地与自动布局一起使用并避免崩溃,还可以将自身锚定到视图而不是窗口?

What you are seeing is the right behaviour. 你所看到的是正确的行为。

The results you are seeing is because of the fact that UIViewController is a UIResponder subclass. 您看到的结果是因为UIViewController是一个UIResponder子类。 By overriding the inputAccessoryView and returning an instance of a view, UIViewController will take care of placing that view at the bottom of the screen and animating it appropriately when keyboard appears or disappears. 通过重写inputAccessoryView并返回视图实例, UIViewController将负责将该视图放置在屏幕底部,并在键盘出现或消失时对其进行适当的动画处理。

If you want to add this bar on top of your keyboard, then you need to set the property inputAccessoryView of a textField/textView to your custom view. 如果要在键盘顶部添加此栏,则需要将textField / inputAccessoryView的属性inputAccessoryView设置为自定义视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM