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

ios 11 jerky on trying to dismiss #42

Open
vargarobert opened this issue Sep 24, 2017 · 7 comments
Open

ios 11 jerky on trying to dismiss #42

vargarobert opened this issue Sep 24, 2017 · 7 comments

Comments

@vargarobert
Copy link

vargarobert commented Sep 24, 2017

There is an issue on ios11. The nav bar gets jerky when pulling to dismiss.
Can be seen in the demo as well.

@ChrisRicca
Copy link

I have been looking into this, but haven't been able to fix it yet. @vargarobert did you end up trying to fix this when you were looking at it?

@vargarobert
Copy link
Author

vargarobert commented Nov 16, 2017 via email

@tklucher
Copy link

I think I might take a crack at it soon. I think it has something to do with safe zones. I have been seeing this a lot on my iPhoneX in testing and when I do the drag super slow it looks like when the animation starts dragging down the height of the object you are dragging gets shorter (specifically at the top on my device by the height of the safe zone above my top element constraint) causing the jerky feeling. At least that is what I am planning to look at as a possible cause.

@matthewweldon
Copy link

In my xp, this is to do with safe area layout guides, if I manually take safe area off and just put a larger constraint for the iPhone x it works.

@ChrisRicca
Copy link

ChrisRicca commented Jan 10, 2018

I found an (unanswered) bug related to this on StackOverflow. I am taking another crack at this but posting here for tracking purposes: https://stackoverflow.com/questions/47638767/ios-11-uinavigationbar-position-loses-status-bar-height-during-transition

Also this Apple forum Post (login required?): https://forums.developer.apple.com/thread/93444

@ChrisRicca
Copy link

I'm not really sure how I would implement this as a fix in PullToDismiss, but if anyone else is looking to work around this:

setting scrollView.contentInsetAdjustmentBehavior = .never on my scroll view did help with the worst of the jumpiness, but the UINavigationController was still shrinking (by the height of the status bar) whenever I started to drag down due to the behavior in the links above.

To deal with this, I wrapped the UINavigationController in a parent view controller, and added a view in that parent view controller that was the same color as my navigationBar. That way, when that slice of the UINavigationController would disappear, you don't see the presenting view behind the status bar suddenly appear.

@ElectroBuddha
Copy link

As far as I could investigate the 'jumpiness' is caused by two things when drag animation starts:

  • the safeAreaLayoutGuide.topAnchor decreases by the height of the status bar (causing the tableView/collectionView/scrollView content to slightly jump up)

  • the navigationBar height shrinks by the height of the status bar (causing the navigationBar content to slightly jump up)

To solve the first issue I override the viewSafeAreaInsetsDidChange() method inside my viewController to compensate for lost safeArea topAnchor height by increasing additionalSafeAreaInsets.top value, like this:

    var navBarHeight: CGFloat {
        return self.navigationController?.navigationBar.frame.size.height ?? 0.0
    }

    var statusBarHeight: CGFloat {
        let statusBarSize = UIApplication.shared.statusBarFrame.size
        return min(statusBarSize.width, statusBarSize.height)
    }
    
    @available(iOS 11, *)
    override func viewSafeAreaInsetsDidChange() {
        super.viewSafeAreaInsetsDidChange()
        
        let totalNavBarHeight = navBarHeight + statusBarHeight
        
        if (self.view.safeAreaInsets.top < totalNavBarHeight) {
            self.additionalSafeAreaInsets.top = totalNavBarHeight - self.view.safeAreaInsets.top
        }
        else if (self.view.safeAreaInsets.top > totalNavBarHeight) {
            self.additionalSafeAreaInsets.top = 0
        }
    }

To solve the navigationBar shrinking height problem, I've modified updateViewPosition(offset: CGFloat) method inside PullToDismiss.swift file, and changed values where it says avoid statusbar gone like this:

    if viewPositionY >= 0 && viewPositionY < 0.005 {
        addOffset = min(max(-0.001, addOffset), 0.001)
    }

To avoid triggering navBar shrinking, I made the drag animation move even more slowly in the beginning, I've changed value 0.05 to 0.005, and values -0.01 and 0.01 to -0.001 and 0.001.

This could probably be fixed more elegantly but for now this is what works for me.

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

5 participants