在 JSQMessagesViewController 中隐藏 inputToolbar

hide the inputToolbar in JSQMessagesViewController

我正在为我的聊天应用程序使用 JSQMessagesViewController。当没有网络时activity我想隐藏inputToolbar

我试过了,但是不行:

    self.inputToolbar.frame.size = CGSize(width: 0,height: 0)

当我设置它时,不到一秒钟它就消失了:

    self.inputToolbar.preferredDefaultHeight = 0

知道怎么做吗? 也许禁用 inputToolbar 也足够好。

事实证明这行得通:

override func viewDidLoad() {
    super.viewDidLoad()
    self.inputToolbar.removeFromSuperview()
}

与其从父视图中删除并不得不添加回子视图,不如使用:

[self.inputToolbar setHidden:YES];

我找到了一个没有任何副作用的更好的解决方案。
您可以在 JSQMessagesViewController 的 descendant class 中进行操作。

1. 将此基础方法 class 提供给您:

@interface JSQMessagesViewController ()
- (void)jsq_setCollectionViewInsetsTopValue:(CGFloat)top 
                                bottomValue:(CGFloat)bottom;
@end

2. 覆盖方法的父实现(大小改变时调用):

- (void)jsq_updateCollectionViewInsets {
    CGFloat topInset = self.topLayoutGuide.length + self.topContentAdditionalInset;
    CGFloat bottomInset = 0.0;
    [self jsq_setCollectionViewInsetsTopValue:topInset bottomValue:bottomInset];
}

3.写永远隐藏输入工具栏的方法:

- (void)hideInputToolbar {
    self.inputToolbar.hidden = YES;
    [self jsq_updateCollectionViewInsets];
}

4.尽情享受吧!