1.1 C
New York
Sunday, February 23, 2025

ios – ScrollView begin below the StatusBar


On the prime of scrollView, I’ve an imageView and i need it to be on the prime of the display however it doesn’t matter what i attempted i couldn’t discover a solution to put it on the highest of the display. It begins below the statusBar. Right here is how is it look:

enter image description here
enter image description here

and that is what i need:

enter image description here

Listed here are the constraints:

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

        contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
        contentView.topAnchor.constraint(equalTo: scrollView.topAnchor),
        contentView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
        contentView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
        contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor),
        
        
        imageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
        imageView.topAnchor.constraint(equalTo: contentView.topAnchor),
        imageView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
        imageView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.45), ]) }

I attempted this however did not repair:

        scrollView.contentInsetAdjustmentBehavior = .by no means

there may be one resolution that labored nevertheless it isnt the very best strategy i consider:

            scrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, fixed: -130),

Once I add a relentless to the highest anchor of the scrollView, it resolves the problem. Nevertheless, on different screens comparable to iPads or iPhone X, I want to regulate this fixed accordingly. I am unsure if calculating the peak of the standing bar after which dynamically adjusting the constraints is the the very best strategy. I really feel like there have to be a neater approach.

Related Articles

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles