3

I am using JSQMessagesViewController for my chat application. When there is no internet activity I would like to hide the inputToolbar

I tried this, but that does not work:

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

When I set this, then for less than a second it's gone:

    self.inputToolbar.preferredDefaultHeight = 0

Any idea how to do this? Maybe disabling the inputToolbar could also be good enough.

Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58

3 Answers3

4

I found a better solution which doesn't have any side effects.
You can make the actions in a descendant class of JSQMessagesViewController.

1. Make this method of base class available for you:

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

2. Override parent realization of method (called when size changed):

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

3. Write the method to hide input toolbar forever:

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

4. Enjoy!

Mikhail
  • 1,061
  • 2
  • 13
  • 30
  • Hi. You mean create a bridging-header? Or just create `customclass.m/h` files? – Edison Jul 10 '16 at 05:52
  • Just create a usual custom class whose parent class is JSQMessagesViewController. Like this: @interface MyMessageViewController : JSQMessagesViewController Then put above code to MyMessageViewController.m file. – Mikhail Jul 10 '16 at 18:16
  • Yes but my project is in Swift so do I need a bridging header file? Since JSQ is already Objective-C I can just create a subclass with new .h and .m and not worry about a header file? – Edison Jul 10 '16 at 18:24
3

Instead of removing from superview and having to add back as a subview, why not just use:

[self.inputToolbar setHidden:YES];

sublimepremise
  • 245
  • 1
  • 2
  • 10
0

It turned out that this will work:

override func viewDidLoad() {
    super.viewDidLoad()
    self.inputToolbar.removeFromSuperview()
}
Edwin Vermeer
  • 13,017
  • 2
  • 34
  • 58
  • You should use the approved awnser – Edwin Vermeer Jul 22 '15 at 14:18
  • When I use this code there is the exception with a reason: 'An instance of class JSQMessagesComposerTextView was deallocated while key value observers were still registered with it. – Mikhail Jul 22 '15 at 14:41