Created
October 24, 2018 14:29
-
-
Save DanielCardonaRojas/4e69706b61b56000f11e9fa84666705a to your computer and use it in GitHub Desktop.
UIScrollView Extensions (scroll to subview and get relative offset of subview)
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