From d57ece42ba5a7de577b6f723cec8fd6648f34ee2 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sat, 16 May 2015 08:25:38 -0700 Subject: [PATCH] =?UTF-8?q?show=20the=20editor=20toolbar=20above=20the=20k?= =?UTF-8?q?eyboard=20when=20it=E2=80=99s=20shown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Blog/Base.lproj/Main.storyboard | 9 +++++--- Blog/EditorViewController.m | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/Blog/Base.lproj/Main.storyboard b/Blog/Base.lproj/Main.storyboard index 7f33cb8..ff15b30 100644 --- a/Blog/Base.lproj/Main.storyboard +++ b/Blog/Base.lproj/Main.storyboard @@ -1,12 +1,12 @@ - + - + FontAwesome FontAwesome @@ -178,8 +178,9 @@ wanted with as little input and thought as possible. - + + @@ -206,6 +207,7 @@ wanted with as little input and thought as possible. + @@ -237,6 +239,7 @@ wanted with as little input and thought as possible. + diff --git a/Blog/EditorViewController.m b/Blog/EditorViewController.m index 367c659..e50edef 100644 --- a/Blog/EditorViewController.m +++ b/Blog/EditorViewController.m @@ -190,7 +190,33 @@ } } +- (UIViewAnimationOptions)animationOptionsForCurve:(UIViewAnimationCurve)curve { + UIViewAnimationOptions options = 0; + if (curve == UIViewAnimationCurveEaseIn) { + options |= UIViewAnimationOptionCurveEaseIn; + } + if (curve == UIViewAnimationCurveEaseOut) { + options |= UIViewAnimationOptionCurveEaseOut; + } + if (curve == UIViewAnimationCurveEaseInOut) { + options |= UIViewAnimationOptionCurveEaseInOut; + } + if (curve == UIViewAnimationCurveLinear) { + options |= UIViewAnimationOptionCurveLinear; + } + return options; +} + - (void)keyboardWillShow:(NSNotification *)note { + NSValue *keyboardFrame = note.userInfo[UIKeyboardFrameEndUserInfoKey]; + CGFloat keyboardHeight = keyboardFrame.CGRectValue.size.height; + NSNumber *durationNumber = note.userInfo[UIKeyboardAnimationDurationUserInfoKey]; + NSNumber *curveNumber = note.userInfo[UIKeyboardAnimationCurveUserInfoKey]; + [UIView animateWithDuration:durationNumber.doubleValue delay:0 options:[self animationOptionsForCurve:curveNumber.integerValue] animations:^{ + self.toolbar.transform = CGAffineTransformMakeTranslation(0, -keyboardHeight); + } completion:nil]; + [self adjustTextViewBottomInset:keyboardHeight]; + if (self.textView.isFirstResponder) { // This notification is called inside an animation block, but we don't want animation here. // Dispatch to break out of the animation. @@ -201,9 +227,23 @@ } - (void)keyboardWillHide:(NSNotification *)note { + NSNumber *durationNumber = note.userInfo[UIKeyboardAnimationDurationUserInfoKey]; + NSNumber *curveNumber = note.userInfo[UIKeyboardAnimationCurveUserInfoKey]; + [UIView animateWithDuration:durationNumber.doubleValue delay:0 options:[self animationOptionsForCurve:curveNumber.integerValue] animations:^{ + self.toolbar.transform = CGAffineTransformIdentity; + } completion:nil]; + [self adjustTextViewBottomInset:0]; [self hideHideKeyboardButton]; } +- (void)adjustTextViewBottomInset:(CGFloat)bottomInset { + UIEdgeInsets inset = self.textView.contentInset; + inset.bottom = bottomInset; + self.textView.contentInset = inset; + // TODO: put the selection in the middle somehow ... can we get the point/rect for the selection? + [self.textView scrollRangeToVisible:self.textView.selectedRange]; +} + - (void)postDeleted:(NSNotification *)note { NSString *path = note.userInfo[PostPathUserInfoKey]; if ([path isEqualToString:self.post.path]) {