Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPad.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7525" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="bI0-rc-sHz">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7516"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Tab Bar Controller-->
<scene sceneID="h1s-Vr-iAg">
<objects>
<tabBarController id="bI0-rc-sHz" sceneMemberID="viewController">
<nil key="simulatedBottomBarMetrics"/>
<tabBar key="tabBar" contentMode="scaleToFill" id="n8m-CH-uXr">
<rect key="frame" x="0.0" y="0.0" width="768" height="49"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</tabBar>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="viewControllers" id="tFA-BL-Ny4"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qkr-V9-Ixo" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-644" y="318"/>
</scene>
<!--Item-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="NPViewController" sceneMemberID="viewController">
Expand All @@ -13,12 +32,11 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<rect key="frame" x="0.0" y="0.0" width="768" height="975"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="9L3-s0-Fal">
<rect key="frame" x="188" y="974" width="391" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<rect key="frame" x="188" y="925" width="391" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="391" id="LN9-at-wOs"/>
<constraint firstAttribute="height" constant="30" id="Vlo-Rq-tQQ"/>
Expand All @@ -30,8 +48,7 @@
</connections>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text field on bottom is moving with keyboard." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fCq-1e-7Pq">
<rect key="frame" x="210" y="502" width="349" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<rect key="frame" x="210" y="477" width="349" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand All @@ -46,6 +63,8 @@
<constraint firstAttribute="bottom" secondItem="9L3-s0-Fal" secondAttribute="bottom" priority="750" constant="20" symbolic="YES" id="pv6-kZ-IpM"/>
</constraints>
</view>
<extendedEdge key="edgesForExtendedLayout" top="YES"/>
<tabBarItem key="tabBarItem" title="Item" id="uVo-fU-Nz8"/>
<connections>
<outlet property="bottomTextField" destination="9L3-s0-Fal" id="g9y-1C-aae"/>
</connections>
Expand Down
35 changes: 27 additions & 8 deletions Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPhone.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7525" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="Uy2-eA-FQD">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7516"/>
</dependencies>
<scenes>
<!--View Controller-->
<!--Tab Bar Controller-->
<scene sceneID="mhI-73-2uo">
<objects>
<tabBarController id="Uy2-eA-FQD" sceneMemberID="viewController">
<nil key="simulatedBottomBarMetrics"/>
<tabBar key="tabBar" contentMode="scaleToFill" id="cov-iX-uAd">
<rect key="frame" x="0.0" y="0.0" width="320" height="49"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</tabBar>
<connections>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="viewControllers" id="kzo-vb-E8B"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="aJa-rX-VQp" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="194" y="477"/>
</scene>
<!--Item-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="NPViewController" sceneMemberID="viewController">
Expand All @@ -13,12 +32,11 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="519"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="kmu-EM-f17">
<rect key="frame" x="20" y="518" width="280" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<rect key="frame" x="20" y="469" width="280" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="2NC-gP-Dl1"/>
</constraints>
Expand All @@ -29,8 +47,7 @@
</connections>
</textField>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text field on bottom is moving with keyboard." lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" preferredMaxLayoutWidth="280" translatesAutoresizingMaskIntoConstraints="NO" id="nRj-ew-XV4">
<rect key="frame" x="20" y="264" width="280" height="41"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<rect key="frame" x="20" y="239" width="280" height="41"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
Expand All @@ -47,6 +64,8 @@
<constraint firstItem="kmu-EM-f17" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="20" symbolic="YES" id="ZK3-h7-vgj"/>
</constraints>
</view>
<extendedEdge key="edgesForExtendedLayout" top="YES"/>
<tabBarItem key="tabBarItem" title="Item" id="b4k-Wm-gRs"/>
<connections>
<outlet property="bottomTextField" destination="kmu-EM-f17" id="QFl-ES-pSN"/>
</connections>
Expand Down
4 changes: 2 additions & 2 deletions NPKeyboardLayoutGuide.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "NPKeyboardLayoutGuide"
s.version = "1.0.0"
s.version = "1.0.1.rc1"
s.summary = "Add layout guide for keyboard to UIViewController"
s.description = <<-DESC
Layout guide for keyboard allows indirecty add constraints to keyboard.
Expand All @@ -18,9 +18,9 @@ Pod::Spec.new do |s|
DESC
s.homepage = "https://github.com/Nodepad/NPKeyboardLayoutGuide"
s.license = 'MIT'
s.author = { "Oleksii Kuchma" => "nod3pad@gmail.com" }
s.source = { :git => "https://github.com/Nodepad/NPKeyboardLayoutGuide.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/oleksiikuchma'
s.author = { "Oleksii Kuchma" => "nod3pad@gmail.com", "Puttin Wong" => "yzwang.nj@gmail.com" }

s.platform = :ios, '6.0'
s.requires_arc = true
Expand Down
9 changes: 8 additions & 1 deletion Pod/Classes/NPKeyboardLayoutGuide.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,14 @@ - (void)keyboardWillChangeFrame:(NSNotification *)notification
CGRect convertedEndFrame = [self.window convertRect:endKeyboardFrame toView:self.superview];
CGRect convertedWindowFrame = [self.window convertRect:windowFrame toView:self.superview];

_verticalPositionConstraint.constant = convertedEndFrame.origin.y - (convertedWindowFrame.origin.y + convertedWindowFrame.size.height);
CGFloat convertedEndKeyboardHeight = CGRectGetHeight(convertedEndFrame);
CGFloat convertedWindowBottomOffset = CGRectGetMaxY(convertedWindowFrame) - CGRectGetMaxY(self.superview.bounds);

BOOL keyboardIsVisible = CGRectGetMinY(endKeyboardFrame) < CGRectGetMaxY(windowFrame);

BOOL needSetVerticalPositionConstraintConstant = keyboardIsVisible && ABS(convertedWindowBottomOffset) < convertedEndKeyboardHeight;

_verticalPositionConstraint.constant = needSetVerticalPositionConstraintConstant ? - (convertedEndKeyboardHeight - convertedWindowBottomOffset) : 0.f;

[UIView animateWithDuration:animationDuration
delay:0
Expand Down