Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertical layout automatic always have height 0 when using UIScrollView inside the sheet. #11

Open
pddkhanh opened this issue Sep 14, 2021 · 0 comments

Comments

@pddkhanh
Copy link

Thank you for your awesome work.
I found there is a use-case that cause the height always is 0 when using UIScrollView inside the sheet ViewController. Could you please help to take a look and suggest how to fix it properly?

Below is the sample ScrollView within ViewController. This ViewController works normal with default presentation.

import UIKit

final class Label: UILabel {
    init(_ text: String) {
        super.init(frame: .zero)
        self.text = text

        textColor = .darkText
    }

    @available(*, unavailable)
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

final class SampleScrollViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let scrollView = UIScrollView()

        let stackView = UIStackView(arrangedSubviews: (1...10).map { Label("Text \($0)") })
        stackView.axis = .vertical
        stackView.spacing = 8
        scrollView.addSubview(stackView)
        view.addSubview(scrollView)

        stackView.translatesAutoresizingMaskIntoConstraints = false
        scrollView.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([
            stackView.topAnchor.constraint(equalTo: scrollView.topAnchor),
            stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
            stackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
            stackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
            stackView.widthAnchor.constraint(equalTo: view.widthAnchor),
        ])

        NSLayoutConstraint.activate([
            scrollView.topAnchor.constraint(equalTo: view.topAnchor),
            scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
            scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
            scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
        ])
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant