ScrollviewParallax icon indicating copy to clipboard operation
ScrollviewParallax copied to clipboard

Let imageView scroll

Open onmyway133 opened this issue 10 years ago • 1 comments

Thanks for the code, you explain better than the original blog :D

With the current implementation, the imageView always pins to the top. Now we have 2 top constraints from the imageView to the TopLayoutGuide (1 with equal, priority 999 and 1 with less than, priority 1000), let call them C1 and C2

This would make it scroll with the scrollView as well

func scrollViewDidScroll(scrollView: UIScrollView) {
        let y = scrollView.contentOffset.y

        if y > 0 {
            c1.constant = -y
            c2.constant = -y
        } else {
            c1.constant = 0
            c2.constant = 0
        }
    }

onmyway133 avatar Oct 20 '15 16:10 onmyway133

I tried putting a heightConstraint on the imageView, and try activate, deactivate those 3 constraints (heightConstraint, C1, C2) but it crashes

func scrollViewDidScroll(scrollView: UIScrollView) {
        let sketchy = scrollView.contentOffset.y <= 0

        heightConstraint.active = !sketchy
        c1.active = sketchy
        c2.active = sketchy
    }

onmyway133 avatar Oct 20 '15 16:10 onmyway133