MarioIannotta / PullUpController

Pull up controller with multiple sticky points like in iOS Maps
MIT License
1.24k stars 141 forks source link

PullUpView doesn't load properly when app loads #46

Open santi-g-s opened 5 years ago

santi-g-s commented 5 years ago

Hi, thanks for the great work you've done. But, when my app initially loads, the view is shown much lower than it should be when collapsed. Once I swipe up to open it, however, it returns to the correct height when collapsed and expanded. I have set the height of the collapsed view to be a view container I have in the PullUpView.

santi-g-s commented 5 years ago

Here is what it should look like when it starts:

img_3912

This is what I get

img_3910

MarioIannotta commented 5 years ago

It is really hard to understand the issue here. My guess here is that you are calling the method addPullUpController(<#T##PullUpController#>, initialStickyPointOffset: <#T##CGFloat#>, animated: <#T##Bool#>) using a wrong value as initialStickyPointOffset or when your view's layout is not ready.

Could you please provide an example of the issue using the demo project?

santi-g-s commented 5 years ago

Here's the code I use to make the pullUpController.

private func makeViewController() -> ViewController {
        let currentPullUpController = children
            .filter({ $0 is ViewController })
            .first as? ViewController
    let pullUpController: ViewController = currentPullUpController ?? UIStoryboard(name: "Main",bundle: nil).instantiateViewController(withIdentifier: "ViewController") as! ViewController
    pullUpController.initialState = .contracted
    if originalPullUpControllerViewSize == .zero {
            originalPullUpControllerViewSize = pullUpController.view.bounds.size
        }
    return pullUpController
    }

I add it to the view with this (had to add 15 so that i can at least see it)

private func addPullUpController() {

        let pullUpController = makeViewController()
        _ = pullUpController.view
        print(pullUpController.initialPointOffset)
        addPullUpController(pullUpController,
                            initialStickyPointOffset: pullUpController.initialPointOffset + 15,
                            animated: true)

    }

The initialPointOffset is set up as follows:

var initialPointOffset: CGFloat {
        switch initialState {
        case .contracted:
            return containerView?.frame.height ?? 0
        case .expanded:
            return pullUpControllerPreferredSize.height
        }
    }

And the prefferedSize comes from the portrait Size.

The confusing bit is that this only happens when the app is loaded initially. After that the sticky points are correct.

evtaccount commented 5 years ago

@santi-g-s navigationBar is the reason