maxep / MXParallaxHeader

Simple parallax header for UIScrollView
MIT License
1.73k stars 251 forks source link

parallaxHeader.view not filling superview. #113

Closed anzfactory closed 4 years ago

anzfactory commented 4 years ago

Issue Description

Environment Information

Reproduction code

import MXParallaxHeader
import UIKit

class ViewController: UIViewController {

    private let tableView: UITableView = {
        let tableView = UITableView(frame: .zero, style: .plain)
        tableView.translatesAutoresizingMaskIntoConstraints = false
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "CELL")
        return tableView
    }()

    private let coverView: UIView = {
        let view = UIView(frame: .zero)
        view.backgroundColor = .blue
        return view
    }()

    override func loadView() {
        super.loadView()

        tableView.dataSource = self
        view.addSubview(tableView)
        NSLayoutConstraint.activate([
            tableView.topAnchor.constraint(equalTo: view.topAnchor),
            tableView.leftAnchor.constraint(equalTo: view.leftAnchor),
            tableView.rightAnchor.constraint(equalTo: view.rightAnchor),
            tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
        ])
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.parallaxHeader.mode = .fill
        tableView.parallaxHeader.view = coverView
        tableView.parallaxHeader.height = 300
        tableView.parallaxHeader.minimumHeight = 10
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        print(tableView.parallaxHeader.contentView.frame) // đŸ¤” (0.0, -344.0, 0.0, 344.0)
        print(tableView.parallaxHeader.view?.frame) // đŸ¤” Optional((0.0, 0.0, 0.0, 344.0))
    }
}

extension ViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 100
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "CELL", for: indexPath)
        cell.textLabel?.text = "Index: \(indexPath.row)"
        return cell
    }
}

Screenshot

by MXParallaxHeader 1.0.0

expected behavior.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.