Here is an image that explains everything I want to do:
My question is, how would I make my view structure. The header of the table view should be fixed at top of the table. But what about the top most image that is above the table view header. Will I have to add the table view inside the UIScrollView ?
Parallax effect can be done by CATransform3D
, but how would I achieve what I want, that is my question. There are lots of demos but I want to make it done custom.
I have wondering how to achieve a parallax sticky header and I found this post that does the work.
The post is in Swift 2 but I have recode it for swift 4.2
CustomHeaderView
And then VieController
Resulting to the video that shows the link provided. Next steps would add the safe area constraint and maybe add nib to the header but that it is completely up to you.
You can add image view to the view like -
After that in tableview delegate method you can add
scrollviewDidScroll
method like -I hope this will be helpful. Please correct me if I am wrong.
Swift 5
as of my requirement i have used https://github.com/maxep/MXParallaxHeader
i explained you the things step by step
you need to install the above mentioned third party library by using this pod command
open up commannd manager(Terminal) go to your target folder and run this command:
you need a parallax effect of your image view and stick the header on the top you need to create the custom
.xib
file to user as a parallax header.you have created UIView now you need to add the Cocoa Touch Class file for your custom view.
now you have pair of class file with its custom UIView eg.(ParallaxView.xib & ParallaxView.swift)
and according to my project requirement i need to add a pagemenu in the bottom of the parallaxheader so i use a another third party library named
CAPSPageMenu
now we are ready to go for the code part.
Goto your ViewController file and import the frame work
delegate methods
Define the class (MyParralax.swift) variables for the controllers (for page menu )and (MXParallaxHeader)like this
you have to create two view controller file as a child view controller of the pagemenu and storyboard too.these both controller.swift (VC1 & VC2) will look like this.
put this three functions in your parent controller(MyParralax.swift)
check this output.