Parallax Effect for iOS with Swift (Part 2)
In previous post, we had used only storyboard to achieve parallax effect for cover photo just like Twitter app. In this post, we are going to implement the similar effect, but for an image inside scrollview, so when we scroll, the image is scrolled but with parallax effect inside, just like this:
Now use project from last post, we are going to add another ImageView into ScrollView content. Here we have constraints of width, height, and spacing to left, right of ScrollView, and spacing to nearest top element:[
Connect it as an Outlet for scroll handling:
[
Set scale mode to Aspect Fill and check Clip Subviews, this will make our ImageView properly displayed without exceed its frame:
[
Note that our label is now overlap with the image, we will adjust that by remove old top constraint of the label, and add another constraint to properly make its top position below ImageView:
[
Now you can run and see your ImageView is properly placed:
[