Swiftgram/Display/ScrollToTopProxyView.swift
2016-06-19 15:14:26 +03:00

33 lines
813 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
}
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
}
}