From ae2b92c2876e3c0c8c8266187ad0eb4ae29fe5a8 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 20 Mar 2021 12:47:37 +0300 Subject: First part of the new chat view keyboard avoiding --- Juick/Main.storyboard | 1 + Juick/ViewControllers/ChatViewController.h | 1 + Juick/ViewControllers/ChatViewController.m | 9 +++++++-- Juick/Views/MessageInputView.xib | 18 +++++++++++------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Juick/Main.storyboard b/Juick/Main.storyboard index fae7c7e..fd673a0 100644 --- a/Juick/Main.storyboard +++ b/Juick/Main.storyboard @@ -105,6 +105,7 @@ + diff --git a/Juick/ViewControllers/ChatViewController.h b/Juick/ViewControllers/ChatViewController.h index f21eb10..f23ecc8 100644 --- a/Juick/ViewControllers/ChatViewController.h +++ b/Juick/ViewControllers/ChatViewController.h @@ -14,6 +14,7 @@ @property(nonatomic, strong) NSMutableArray *messages; @property(nonatomic, strong) NSString *uname; @property (weak, nonatomic) IBOutlet UIStackView *stack; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *stackBottomConstraint; @property (strong, nonatomic) IBOutlet UITableView *tableView; -(void) reloadChat; diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m index 9493155..cfecc48 100644 --- a/Juick/ViewControllers/ChatViewController.m +++ b/Juick/ViewControllers/ChatViewController.m @@ -11,6 +11,8 @@ #import "MessageInputView.h" +#define kMessageInputInitialHeight 50 + @interface ChatViewController () @property (nonatomic, readwrite, retain) MessageInputView *accessoryView; @@ -37,6 +39,8 @@ [self addObserver:self forKeyPath:@"uname" options:0 context:nil]; #if TARGET_OS_MACCATALYST [self.stack addArrangedSubview:[self inputAccessoryView]]; +#else + self.stackBottomConstraint.constant = kMessageInputInitialHeight; #endif } @@ -102,11 +106,12 @@ if (userInfo) { CGRect beginFrame = [userInfo [UIKeyboardFrameBeginUserInfoKey] CGRectValue]; CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; - CGFloat delta = endFrame.origin.y - beginFrame.origin.y; + CGFloat keyboardHeight = endFrame.origin.y - beginFrame.origin.y; CGFloat duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue]; UIViewAnimationCurve animationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]; + [UIView animateWithDuration:duration delay:0 options:(animationCurve << 16) animations:^{ - self.tableView.contentOffset = CGPointMake(0, self.tableView.contentOffset.y - delta); + self.tableView.contentOffset = CGPointMake(0, self.tableView.contentOffset.y - keyboardHeight); } completion:nil]; } } diff --git a/Juick/Views/MessageInputView.xib b/Juick/Views/MessageInputView.xib index e13beca..76d72c9 100644 --- a/Juick/Views/MessageInputView.xib +++ b/Juick/Views/MessageInputView.xib @@ -1,11 +1,12 @@ - + - + + @@ -20,14 +21,14 @@ - - + @@ -38,7 +39,7 @@ -