Google Primer app for iOS has a table view scrolling effect where the cells stack on top of each other while scrolling. Primer application : you can kinda see the effect if you scroll on their page... The effect I am talking about is in the featured lessons of Primer. I am trying to reproduce it with a tableview.
I have tried playing with the frame of the cell on the viewdidscroll event. I got it working but it gets very jumpy/jerky when moving up in a certain way. Also, when the jerk happens, the frame gets offset incorrectly. I was only able to do it on the frame of a label inside the cells. My cells are really big(more then half of the screen).
How can I eliminate the jumping/jerk ? How can I animate the container view position instead of the label position ?
Current animation on the scrollViewDidScroll with a label :
override func scrollViewDidScroll(scrollView: UIScrollView) {
if (self.tableView.contentOffset.y < 0) { return }
let offsetYDifference = oldYOffset - self.tableView.contentOffset.y
oldYOffset = self.tableView.contentOffset.y
let cell = self.tableView.visibleCells.first!
var newOriginY = (cell.textLabel?.frame.origin.y)! - offsetYDifference
if (newOriginY < 0) { //Cells get reused.
newOriginY = newOriginY + cell.frame.height
}
cell.textLabel?.frame = CGRect(x: (cell.textLabel?.frame.origin.x)!,
y: newOriginY,
width: (cell.textLabel?.frame.width)!,
height: (cell.textLabel?.frame.height)!)
}
Custom paging-like behavior with paging enabled set to off on the storyboard :
override func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let offsety = targetContentOffset.memory.y
var smallestCellDiffToContentOffset = abs(offsety - (self.tableView.visibleCells.first?.frame.origin.y)!)
var closestCellOrigin = self.tableView.visibleCells.first?.frame.origin.y
self.tableView.visibleCells.forEach { (cell) -> () in
if (abs(offsety - cell.frame.origin.y) <= smallestCellDiffToContentOffset) {
smallestCellDiffToContentOffset = abs(offsety - cell.frame.origin.y)
closestCellOrigin = cell.frame.origin.y
}
}
targetContentOffset.memory.y = closestCellOrigin!
}
I am a beginner swift developper and I am really clueless on what the do. Thanks in advance.