Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d629e0

Browse files
committed
Support the view controller be embedded in container view
Calculate the bottom margin to its enclosing window. This unifies `appropriateTabBarHeight` consideration.
1 parent 359ae41 commit 7d629e0

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

Examples/Messenger/Messenger-Storyboard/Base.lproj/Main.storyboard

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6245" systemVersion="14A386a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="nJp-d0-Z0H">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="0WO-Kt-Oxc">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6238"/>
4+
<deployment identifier="iOS"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6246"/>
56
</dependencies>
67
<scenes>
78
<!--Message View Controller-->
@@ -23,10 +24,29 @@
2324
</objects>
2425
<point key="canvasLocation" x="1302" y="492"/>
2526
</scene>
26-
<!--Navigation Controller-->
27+
<!--Tab Bar Controller-->
28+
<scene sceneID="SEt-8k-R87">
29+
<objects>
30+
<tabBarController id="0WO-Kt-Oxc" sceneMemberID="viewController">
31+
<nil key="simulatedBottomBarMetrics"/>
32+
<tabBar key="tabBar" contentMode="scaleToFill" id="US0-fN-o9u">
33+
<rect key="frame" x="0.0" y="0.0" width="320" height="49"/>
34+
<autoresizingMask key="autoresizingMask"/>
35+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
36+
</tabBar>
37+
<connections>
38+
<segue destination="nJp-d0-Z0H" kind="relationship" relationship="viewControllers" id="nd7-Np-oUR"/>
39+
</connections>
40+
</tabBarController>
41+
<placeholder placeholderIdentifier="IBFirstResponder" id="bQn-nb-Tgr" userLabel="First Responder" sceneMemberID="firstResponder"/>
42+
</objects>
43+
<point key="canvasLocation" x="-132" y="492"/>
44+
</scene>
45+
<!--Tab-->
2746
<scene sceneID="5B4-6e-pdF">
2847
<objects>
2948
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="nJp-d0-Z0H" sceneMemberID="viewController">
49+
<tabBarItem key="tabBarItem" title="Tab" image="icn_editing" id="whH-lj-Whp"/>
3050
<toolbarItems/>
3151
<navigationBar key="navigationBar" contentMode="scaleToFill" id="fWe-MD-oZ3">
3252
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
@@ -42,4 +62,7 @@
4262
<point key="canvasLocation" x="583" y="492"/>
4363
</scene>
4464
</scenes>
65+
<resources>
66+
<image name="icn_editing" width="24" height="24"/>
67+
</resources>
4568
</document>

Source/Classes/SLKTextViewController.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ - (CGFloat)appropriateKeyboardHeight:(NSNotification *)notification
449449
}
450450
}
451451

452-
keyboardHeight -= [self appropriateTabBarHeight];
452+
keyboardHeight -= [self appropriateBottomMarginToWindow];
453453
keyboardHeight -= CGRectGetHeight(self.textView.inputAccessoryView.bounds);
454454

455455
if (keyboardHeight < 0) {
@@ -472,13 +472,12 @@ - (CGFloat)appropriateScrollViewHeight
472472
else return roundf(height);
473473
}
474474

475-
- (CGFloat)appropriateTabBarHeight
475+
- (CGFloat)appropriateBottomMarginToWindow
476476
{
477-
if (self.tabBarController.tabBar.isHidden || self.hidesBottomBarWhenPushed) {
478-
return 0.0;
479-
}
480-
481-
return CGRectGetHeight(self.tabBarController.tabBar.frame);
477+
UIWindow *window = self.view.window;
478+
CGRect convertedRect = [self.view convertRect:self.view.bounds toView:window];
479+
CGFloat bottomMargin = CGRectGetMaxY(window.frame) - CGRectGetMaxY(convertedRect);
480+
return bottomMargin;
482481
}
483482

484483
- (NSString *)appropriateKeyboardNotificationName:(NSNotification *)notification
@@ -946,7 +945,7 @@ - (BOOL)detectExternalKeyboardInNotification:(NSNotification *)notification
946945

947946
if (!self.isMovingKeyboard) {
948947
CGFloat maxKeyboardHeight = keyboardFrame.origin.y + keyboardFrame.size.height;
949-
maxKeyboardHeight -= [self appropriateTabBarHeight];
948+
maxKeyboardHeight -= [self appropriateBottomMarginToWindow];
950949

951950
return (maxKeyboardHeight > CGRectGetHeight(self.view.bounds));
952951
}

0 commit comments

Comments
 (0)