Lenny1357 Lenny1357 - 1 year ago 81
Swift Question

How to trigger an animation when UIScrollView is scrolled to maxY? SWIFT

I have a scroll view and I want an animation to start when the scrollview is scrolled to its end and a little bit further (+75 px). How is that possible? I thought about an if-condition (if view.bounds.maxy >= 1075). But how can this condition or function be called when the user scrolls?


First, make sure your ViewController is a subclass of UIScrollViewDelegate. Next, you want to set your scrollView's delegate to self in the ViewDidLoad(). Then, you'll want to use scrollViewDidScroll() and handle things from there.

func scrollViewDidScroll(scrollView: UIScrollView) {

    if scrollView.contentOffset.y >= 75.0 {
        // Your animation code goes HERE... //