diff --git a/Riot/Categories/UIScrollView.swift b/Riot/Categories/UIScrollView.swift index ff4548c5a..953be01e5 100644 --- a/Riot/Categories/UIScrollView.swift +++ b/Riot/Categories/UIScrollView.swift @@ -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) + } + } }