Last active
June 4, 2020 17:44
-
-
Save DanielCardonaRojas/7e42e909eb585d58f974271307cc22db to your computer and use it in GitHub Desktop.
ScrollView extensions
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 characters
extension UIScrollView { | |
func scrollSubViewToTop(_ subview: UIView, offset: CGFloat, animated: Bool) { | |
let point = convert(subview.frame.origin, from: subview.superview ?? subview) | |
setContentOffset(CGPoint(x: 0, y: point.y - offset), animated: animated) | |
} | |
func viewPortOffset(of subview: UIView) -> CGFloat { | |
let point = convert(subview.frame.origin, from: subview.superview ?? subview) | |
return point.y - contentOffset.y | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment