The effect is the same as Https://github.com/jberlana/JBParallaxCell. Implements the cell's rolling parallax.
The principle is very simple, is a equal ratio formula
Cell picture position/cell picture can slide the total length = cell in table position/cell can slide total length
Implementation method:
1. Add the parent view UIView on the cell's Uiimageview , Clipstobounds is set to Yes, which is used to cut the Uiimageview and limit its size.
2 " in the VC
-(void) Scrollviewdidscroll: ( Uiscrollview *) ScrollView
To update the picture location of each cell in real time.
The code is as follows
-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{for (Weltableviewcell * cell in [Self.tableview Visiblecells]) { cell.image.frame = cgrectoffset (cell.image.frame, 0, ((Cell.image.frame.size.height- Cell.imageFrameView.frame.size.height) * ((CELL.FRAME.ORIGIN.Y + cell.imageFrameView.frame.size.height- SELF.TABLEVIEW.CONTENTOFFSET.Y)/(Self.tableView.frame.size.height + cell.imageFrameView.frame.size.height * 2)) + Cell.imageframeview.frame.size.height-cell.image.frame.size.height)-CELL.IMAGE.FRAME.ORIGIN.Y);} }
PS: Really is a line of code, haha. In fact, a line of code is just a gimmick, you can write more than a few lines to increase readability. The reason to write a line of code is to express this effect is actually quite simple. The offset is calculated by using a calculation, and the frame is reset.
3 "After the initial refresh of TableView, call
[self scrollviewdidscroll:nil];
For example
-(void) Viewdidappear: (BOOL) animated
{
[superviewdidappear:YES];
[self scrollviewdidscroll:nil];
}
Finally, attach the source code demo (post not easy, to get an integral, haha)
Simple demo (with notes)
Above