Add a method to UIScrollView to scroll to bottom

This commit is contained in:
ismailgulek 2022-06-13 18:16:07 +03:00
parent 3fd70eb186
commit c14acb8889
No known key found for this signature in database
GPG key ID: E96336D42D9470A9

View file

@ -30,5 +30,18 @@ extension UIScrollView {
self.scrollRectToVisible(rect, animated: animated)
}
}
/// Scroll to bottom of the receiver.guard let self = self else { return }
/// - Parameter animated: animate the scroll
@objc func vc_scrollToBottom(animated: Bool = true) {
guard contentSize.height >= bounds.height else {
return
}
let bottomOffset = CGPoint(x: 0, y: contentSize.height - bounds.height + contentInset.bottom)
if contentOffset != bottomOffset {
// scroll only if not already there
setContentOffset(bottomOffset, animated: animated)
}
}
}