 
 /*
  
- This view will be stretched when the user pans a scroll
- view in the negative scroll direction, then scroll with
- the scroll view when its content is scrolled.
+ This view is stretched out when the user drags a scroll
+ view (e.g. table view) in the negative scroll direction.
  
  To use this view with a table view, first add it as the
- table header view. Then, call setup(in:) in viewDidLoad.
- Finally call handleScroll(in:) in scrollViewDidScroll(:).
+ table header view, then call handleScroll(in:) whenever
+ scrollViewDidScroll(:) is triggered.
  
  */
 
 import UIKit
 
+
 open class StretchableHeaderView: UIView {
 
     
-    // MARK: - Initialization
-    
-    public convenience init() {
-        self.init(frame: CGRect.zero)
-        setup()
-    }
-    
-    public override init(frame: CGRect) {
-        super.init(frame: frame)
-        setup()
-    }
-    
-    required public init?(coder aDecoder: NSCoder) {
-        super.init(coder: aDecoder)
-        setup()
-    }
+    // MARK: - View Lifecycle
     
     open override func layoutSubviews() {
         super.layoutSubviews()

    
    // MARK: - Properties
    
    fileprivate var baseHeight: CGFloat!
    
    
    
    // MARK: - Public Functions
    
    open func handleScroll(in scrollView: UIScrollView) {
        frame = getNewFrame(in: scrollView)
    }
    
    open func setup(in tableView: UITableView?) {
        guard let tableView = tableView else { return }
        guard self == tableView.tableHeaderView else { return }
        let height = frame.size.height

fileprivate extension StretchableHeaderView {
    
    func isStretching(in scrollView: UIScrollView) -> Bool {
        return scrollView.contentOffset.y < -initialHeight
    }
    
    func getNewFrame(in scrollView: UIScrollView) -> CGRect {
        let width = scrollView.bounds.width
        var rect = CGRect(x: 0, y: -initialHeight, width: width, height: initialHeight)
        guard isStretching(in: scrollView) else { return rect }
        rect.origin.y = scrollView.contentOffset.y
        rect.size.height = -scrollView.contentOffset.y
        return rect
    }
}
