Skip to content

Instantly share code, notes, and snippets.

@ssebi
Last active July 2, 2019 06:25
Show Gist options
  • Save ssebi/7164c6817a7b5bd1a95189584443ed53 to your computer and use it in GitHub Desktop.
Save ssebi/7164c6817a7b5bd1a95189584443ed53 to your computer and use it in GitHub Desktop.
Extension to scroll a UIScrollView to any other view, leaving that view on top of the screen after scrolling.
extension UIScrollView {
func scrollToView(view:UIView, animated: Bool) {
if let origin = view.superview {
let childStartPoint = origin.convert(view.frame.origin, to: self)
self.scrollRectToVisible(CGRect(x: 0.0,
y: childStartPoint.y,
width: 1.0,
height: self.frame.height),
animated: animated)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment