Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide the inputToolbar in JSQMessagesViewController

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.

like image 219
Edwin Vermeer Avatar asked Dec 01 '25 06:12

Edwin Vermeer


2 Answers

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!

like image 65
Mikhail Avatar answered Dec 03 '25 18:12

Mikhail


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

[self.inputToolbar setHidden:YES];

like image 36
sublimepremise Avatar answered Dec 03 '25 20:12

sublimepremise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!