show the editor toolbar above the keyboard when it’s shown

This commit is contained in:
Sami Samhuri 2015-05-16 08:25:38 -07:00
parent a34d5875ee
commit d57ece42ba
2 changed files with 46 additions and 3 deletions

View file

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="H1p-Uh-vWS">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7702" systemVersion="14E17e" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="H1p-Uh-vWS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<customFonts key="customFonts">
<mutableArray key="FontAwesome.ttf">
<mutableArray key="FontAwesome.otf">
<string>FontAwesome</string>
<string>FontAwesome</string>
</mutableArray>
@ -178,8 +178,9 @@ wanted with as little input and thought as possible.</string>
<outlet property="delegate" destination="JEX-9P-axG" id="vKD-HY-lGQ"/>
</connections>
</textView>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" barStyle="black" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YUD-Xe-6Cc">
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YUD-Xe-6Cc">
<rect key="frame" x="0.0" y="492" width="600" height="44"/>
<color key="backgroundColor" red="0.13333333333333333" green="0.13333333333333333" blue="0.13333333333333333" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<items>
<barButtonItem title="Publish" id="qEb-VA-ueB">
<connections>
@ -206,6 +207,7 @@ wanted with as little input and thought as possible.</string>
<color key="tintColor" red="0.7953414352" green="0.0" blue="0.013255690590000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="D5w-s5-7oj" firstAttribute="top" secondItem="SYR-Wa-9uf" secondAttribute="bottom" id="0ff-4l-Opw"/>
<constraint firstItem="GAO-Cl-Wes" firstAttribute="top" secondItem="wrG-1y-ZY3" secondAttribute="bottom" constant="44" id="2YF-66-wa8"/>
<constraint firstAttribute="centerX" secondItem="Cwh-4G-e0V" secondAttribute="centerX" id="3Hg-As-HnU"/>
<constraint firstItem="Cwh-4G-e0V" firstAttribute="width" secondItem="svH-Pt-448" secondAttribute="width" id="3dn-X1-5mN"/>
<constraint firstItem="HlE-1R-AqU" firstAttribute="width" relation="lessThanOrEqual" secondItem="svH-Pt-448" secondAttribute="width" constant="-16" id="4Oy-n1-WtG"/>
@ -237,6 +239,7 @@ wanted with as little input and thought as possible.</string>
<exclude reference="EKu-59-ks3"/>
<exclude reference="dyd-fn-rUM"/>
<exclude reference="tUU-ig-gJV"/>
<exclude reference="iTL-zi-eKI"/>
</mask>
</variation>
</view>

View file

@ -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]) {