Edwin Vermeer
Edwin Vermeer

Reputation: 13127

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.

Upvotes: 3

Views: 2256

Answers (3)

Mikhail
Mikhail

Reputation: 1071

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!

Upvotes: 4

sublimepremise
sublimepremise

Reputation: 255

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

[self.inputToolbar setHidden:YES];

Upvotes: 3

Edwin Vermeer
Edwin Vermeer

Reputation: 13127

It turned out that this will work:

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

Upvotes: 0

Related Questions