My table view cells contain a circle in an UIView
, indicating a value. I want to add the UIKit Dynamics
attachment behaviour to that circle in order to for it to lag a bit when scrolling.
I don't want to attach the individual cells to each other but only the circle view to the UITableViewCell
. The rest of the cell should scroll as usual.
Problem: The UITableViewCell
has its origin always at (0, 0)
. How can I add the circle to a view that actually does move when scrolling?
You can change the
anchorPoint
ofUIAttachmentBehavior
during-[scrollViewDidScroll:]
. You may refer to the following code snippet:Preview:
I finally got it to work. The
UITableView
moves the coordinate system of every cell and of all views contained within that cell. Therefor I needed to manually move my view inside theUITableViewCell
during scrolling while still referring to the initial anchor point.The table view controller:
The table view cell: