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/ViewControllers/ChatViewController.h | 1 + Juick/ViewControllers/ChatViewController.m | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Juick/ViewControllers') 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]; } } -- cgit v1.2.3