diff --git a/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPad.storyboard b/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPad.storyboard index f188653..fcd2324 100644 --- a/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPad.storyboard +++ b/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPad.storyboard @@ -1,10 +1,29 @@ - + - + + - + + + + + + + + + + + + + + + + + + + @@ -13,12 +32,11 @@ - + - - + @@ -30,8 +48,7 @@ + + diff --git a/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPhone.storyboard b/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPhone.storyboard index 78880f5..827f36a 100644 --- a/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPhone.storyboard +++ b/Example/NPKeyboardLayoutGuide/Base.lproj/Main_iPhone.storyboard @@ -1,10 +1,29 @@ - + - + + - + + + + + + + + + + + + + + + + + + + @@ -13,12 +32,11 @@ - + - - + @@ -29,8 +47,7 @@ + + diff --git a/NPKeyboardLayoutGuide.podspec b/NPKeyboardLayoutGuide.podspec index 927ebd5..b61a2ec 100644 --- a/NPKeyboardLayoutGuide.podspec +++ b/NPKeyboardLayoutGuide.podspec @@ -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. @@ -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 diff --git a/Pod/Classes/NPKeyboardLayoutGuide.m b/Pod/Classes/NPKeyboardLayoutGuide.m index 9a0e55d..ff81337 100644 --- a/Pod/Classes/NPKeyboardLayoutGuide.m +++ b/Pod/Classes/NPKeyboardLayoutGuide.m @@ -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