0
votes

To explain my problem, I will show you a screenshot of what happens.
After that, I will show the storyboard and the code that I use.
There are actually two problems, which I think are related.

My app UI looks as follows:

enter image description here

When scrolling down, I get the following behaviour:

enter image description here

Navigationbar and tabbar disappear, this is desired behaviour.
Note the white bar below the red bar, this is not desired behaviour and I'm not sure where it comes from.

Edit When making the NewsfeedPageCell blue, I get the following:

enter image description here

When scrolling back to the top, the result is:

enter image description here

Suddenly the newsfeed rendered is positioned too high.

My storyboard looks as follows:

enter image description here

The newsfeed rendered is a reusable View that is loaded from an xib.
Edit: the newsfeed item cell is a reusable view loaded from an xib. As far as I know, I have added all the required anchors in the storyboard.

The code of my Newsfeed class that handles the visibility of the navigationbar and the tabbar on scroll:

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
    // Remove navigationbar and tabbar on scroll
    if(velocity.y > 0) {
        parentViewController?.navigationController?.setNavigationBarHidden(true, animated: true)
        parentViewController?.tabBarController?.hideTabBarAnimated(hide: true)
    } else {
        parentViewController?.navigationController?.setNavigationBarHidden(false, animated: true)
        parentViewController?.tabBarController?.hideTabBarAnimated(hide: false)
    }
}

I've been stuck with this problem for a while.
Any help is appreciated, and if you need more info, please ask.

Edit: The constraints are as follows:

enter image description here

Constraints for the Newsfeed Pager:

enter image description here

Edit2: Debug view navbar hidden:

enter image description here

Debug view without navbar hidden:

enter image description here

2
can you please post a screenshot of your constraints? It seems to top anchor is incorrectTal Zion
@TalZion Added the constraints. When I don't change the setNavigationBarHidden to false, the constraints don't show any strange behaviour.html_programmer
another screenshot please ;-), run the app and start the view debugger, with navbar hidden and withoutTal Zion
The screenshots need to show a 3D stack, so we can know which view/constraint is the issue. There are a few possible problems here, I just want to make sure which one before posting an answer. In the meantime as a quick fix, set the view,backgroundColor to .redTal Zion
@TalZion I edited the screenshots, not sure if it helps. Not sure what you mean with settings background-color to red, the margin will still be there. And after scrolling back upwards (second screenshot debug), the newsfeed now renders too high when the top is reached (it would appear to be the same amount of the white bar though I'm not sure).html_programmer

2 Answers

0
votes

Looks like the top anchor of the menu is to the status bar.

Try:

  1. Change MenuBar.top to superview.top, instead of Safe Layout.tom

  2. As a quick fix:

     override viewDidLoad() {
    
           super.viewDidLoad()
          view.backgroundColor = .red /// or the MenuBar backgroundColor tiny color
       }
    
0
votes

I think y implement all things right. if you face the problem devices ios 11.0+ then the problem is UIScrollViewContentInsetAdjustmentBehavior when navigation bar is hidden which is UIScollView behavior

you need to set

self.collectionView.contentInsetAdjustmentBehavior = .never

the default value for it is .automatic so scroll starting after the status bar.