From 5cb1868974d4b419042b6f0593e7345c3d232113 Mon Sep 17 00:00:00 2001 From: hackiftekhar Date: Fri, 24 Apr 2015 12:34:02 +0530 Subject: [PATCH] Fixed #204 for Swift, --- IQKeybordManagerSwift/IQKeyboardManager.swift | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/IQKeybordManagerSwift/IQKeyboardManager.swift b/IQKeybordManagerSwift/IQKeyboardManager.swift index 49ca78830..a4deff69f 100644 --- a/IQKeybordManagerSwift/IQKeyboardManager.swift +++ b/IQKeybordManagerSwift/IQKeyboardManager.swift @@ -422,7 +422,11 @@ class IQKeyboardManager: NSObject, UIGestureRecognizerDelegate { */ var shouldAdoptDefaultKeyboardAnimation = true - + /** + If YES, then calls 'setNeedsLayout' and 'layoutIfNeeded' on any frame update of to viewController's view. + */ + var layoutIfNeededOnUpdate = true + ///------------------------------------ /// MARK: Class Level disabling methods ///------------------------------------ @@ -700,10 +704,14 @@ class IQKeyboardManager: NSObject, UIGestureRecognizerDelegate { unwrappedController.view.frame = frame self._IQShowLog("Set \(controller?._IQDescription()) frame to : \(frame)") - //Animating content (Bug ID: #160) - unwrappedController.view.setNeedsLayout() - unwrappedController.view.layoutIfNeeded() - + //Animating content if needed (Bug ID: #204) + if layoutIfNeededOnUpdate == true { + //Animating content (Bug ID: #160) + unwrappedController.view.setNeedsLayout() + unwrappedController.view.layoutIfNeeded() + } + + }) { (animated:Bool) -> Void in} } else { // If can't get rootViewController then printing warning to user. _IQShowLog("You must set UIWindow.rootViewController in your AppDelegate to work with IQKeyboardManager") @@ -1330,9 +1338,12 @@ class IQKeyboardManager: NSObject, UIGestureRecognizerDelegate { // Setting it's new frame rootViewController.view.frame = self._topViewBeginRect - //Animating content (Bug ID: #160) - rootViewController.view.setNeedsLayout() - rootViewController.view.layoutIfNeeded() + //Animating content if needed (Bug ID: #204) + if layoutIfNeededOnUpdate == true { + //Animating content (Bug ID: #160) + rootViewController.view.setNeedsLayout() + rootViewController.view.layoutIfNeeded() + } }) { (finished) -> Void in }