Skip to content

Instantly share code, notes, and snippets.

@DanielCardonaRojas
Last active June 4, 2020 17:44
Show Gist options
  • Save DanielCardonaRojas/7e42e909eb585d58f974271307cc22db to your computer and use it in GitHub Desktop.
Save DanielCardonaRojas/7e42e909eb585d58f974271307cc22db to your computer and use it in GitHub Desktop.
ScrollView extensions
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