-
-
Save hanishassim/d5ddc5eb1c752d041df42f75f346d6a3 to your computer and use it in GitHub Desktop.
Revisions
-
louisdh revised this gist
Jun 26, 2017 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -85,11 +85,11 @@ extension UIViewAnimationOptions { case .easeIn: self = .curveEaseIn case .easeOut: self = .curveEaseOut case .easeInOut: self = .curveEaseInOut case .linear: self = .curveLinear } } } -
louisdh revised this gist
Jun 26, 2017 . No changes.There are no files selected for viewing
-
louisdh revised this gist
Jun 26, 2017 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -80,11 +80,11 @@ class NYSKeyboardHelper: NSLayoutConstraint { } extension UIViewAnimationOptions { init(curve: UIViewAnimationCurve) { switch curve { case .easeIn: self = .curveEaseIn case .easeOut: self = .curveEaseOut case .easeInOut: self = .curveEaseInOut -
louisdh revised this gist
Jun 26, 2017 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,11 +16,11 @@ class NYSKeyboardHelper: NSLayoutConstraint { setup() } override func awakeFromNib() { super.awakeFromNib() setup() } private func setup() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeVisible(notification:)), name: .UIKeyboardWillHide, object: nil) @@ -46,7 +46,7 @@ class NYSKeyboardHelper: NSLayoutConstraint { return } let userInfo = notification.userInfo var animationDuration: TimeInterval = 0.0 var animationOptions: UIViewAnimationOptions = [] @@ -69,7 +69,7 @@ class NYSKeyboardHelper: NSLayoutConstraint { let offset = contentAbsoluteFrame.maxY - endFrame.minY + extraIndent let keyboardHeight = max(0, offset) animationOptions.update(with: .layoutSubviews) UIView .animate(withDuration: animationDuration, delay: 0.0, options: animationOptions, animations: { self.constant = keyboardHeight -
louisdh revised this gist
Jun 26, 2017 . 1 changed file with 37 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // NYSKeyboardHelper.swift // B-NYS GCV // // Created by Matthias Nys on 18/03/2017. // Copyright © 2017 B-NYS. All rights reserved. // @@ -15,7 +15,13 @@ class NYSKeyboardHelper: NSLayoutConstraint { super.init() setup() } override func awakeFromNib() { super.awakeFromNib() setup() } private func setup() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeVisible(notification:)), name: .UIKeyboardWillHide, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeVisible(notification:)), name: .UIKeyboardWillShow, object: nil) @@ -39,33 +45,51 @@ class NYSKeyboardHelper: NSLayoutConstraint { print("NYSKEYBOARDHELPER: Fist item needs a superview of the type UIView") return } let userInfo = notification.userInfo var animationDuration: TimeInterval = 0.0 var animationOptions: UIViewAnimationOptions = [] var endFrame = CGRect.zero if let animationCurve = userInfo?[UIKeyboardAnimationCurveUserInfoKey] as? UIViewAnimationCurve { animationOptions = UIViewAnimationOptions(curve: animationCurve) } if let animationDurationFromUserInfo = userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval { animationDuration = animationDurationFromUserInfo } if let endFrameFromUserInfo = userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect { endFrame = endFrameFromUserInfo } let contentAbsoluteFrame = superview.convert(firstItem.frame, to: nil) //To nil -> On the Window let offset = contentAbsoluteFrame.maxY - endFrame.minY + extraIndent let keyboardHeight = max(0, offset) animationOptions.update(with: .layoutSubviews) UIView .animate(withDuration: animationDuration, delay: 0.0, options: animationOptions, animations: { self.constant = keyboardHeight firstItem.layoutIfNeeded() }, completion: nil) } } extension UIViewAnimationOptions { init(curve: UIViewAnimationCurve) { switch curve { case .easeIn: self = .curveEaseIn case .easeOut: self = .curveEaseOut case .easeInOut: self = .curveEaseInOut case .linear: self = .curveLinear } } } -
matthiasnys created this gist
May 26, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ // // NYSKeyboardHelper.swift // B-NYS GCV // // Created by Matthias on 18/03/2017. // Copyright © 2017 B-NYS. All rights reserved. // import UIKit class NYSKeyboardHelper: NSLayoutConstraint { @IBInspectable var extraIndent: CGFloat = 0.0 override init() { super.init() setup() } private func setup() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeVisible(notification:)), name: .UIKeyboardWillHide, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeVisible(notification:)), name: .UIKeyboardWillShow, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeVisible(notification:)), name: .UIKeyboardDidShow, object: nil) } deinit { NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil) NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil) NotificationCenter.default.removeObserver(self, name: .UIKeyboardDidShow, object: nil) } @objc private func keyboardDidChangeVisible(notification: Notification) { guard let firstItem = self.firstItem as? UIView else { print("NYSKEYBOARDHELPER: Fist item needs to be a UIView") return } guard let superview = firstItem.superview else { print("NYSKEYBOARDHELPER: Fist item needs a superview of the type UIView") return } var animationDuration: TimeInterval = 0.0 var animationOptions: UIViewAnimationOptions = UIViewAnimationOptions(rawValue: 0) var endFrame = CGRect.zero if let animationCurve = notification.userInfo?[UIKeyboardAnimationCurveUserInfoKey] as? UIViewAnimationCurve { animationOptions = UIViewAnimationOptions(rawValue: UInt(animationCurve.rawValue << 16)) } if let animationDurationFromUserInfo = notification.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? TimeInterval { animationDuration = animationDurationFromUserInfo } if let endFrameFromUserInfo = notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? CGRect { endFrame = endFrameFromUserInfo } let contentAbsoluteFrame = superview.convert(firstItem.frame, to: nil) //To nil -> On the Window let offset = contentAbsoluteFrame.maxY - endFrame.minY + extraIndent let keyboardHeight = max(0, offset) animationOptions = UIViewAnimationOptions(rawValue: animationOptions.rawValue | UIViewAnimationOptions.layoutSubviews.rawValue) UIView .animate(withDuration: animationDuration, delay: 0.0, options: animationOptions, animations: { self.constant = keyboardHeight firstItem.layoutIfNeeded() }, completion: nil) } }