Files
Swiftgram/submodules/Display/Display/ScrollToTopProxyView.swift
Peter 8f5a4f7dc1 Add 'submodules/Display/' from commit '7bd11013ea936e3d49d937550d599f5816d32560'
git-subtree-dir: submodules/Display
git-subtree-mainline: 9bc996374f
git-subtree-split: 7bd11013ea
2019-06-11 18:44:37 +01:00

36 lines
937 B
Swift

import UIKit
class ScrollToTopView: UIScrollView, UIScrollViewDelegate {
var action: (() -> Void)?
override init(frame: CGRect) {
super.init(frame: frame)
self.delegate = self
self.scrollsToTop = true
if #available(iOSApplicationExtension 11.0, *) {
self.contentInsetAdjustmentBehavior = .never
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override var frame: CGRect {
didSet {
let frame = self.frame
self.contentSize = CGSize(width: frame.width, height: frame.height + 1.0)
self.contentOffset = CGPoint(x: 0.0, y: 1.0)
}
}
@objc func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
if let action = self.action {
action()
}
return false
}
}