Home / IOS Development / CADisplayLink timer animation, get an exact origin of the view. : iOS Programming

CADisplayLink timer animation, get an exact origin of the view. : iOS Programming



Hi, I’m experimenting with MessageKit and trying to implement gradient background messages using a UICollectionView.

See here for demonstration Example of video scrolling and animation.

My setup is that I placed a gradient as the background for UICollectionView, I give the cells that should have a gradient a clear background, and I use a mask on the gradient (collectionView background) which is a combination of the layer. each cell.

I’m updating the mask scrollView(didScroll:), and it works fine, but the problem occurs when I have to update the mask when no scrolling has occurred (for example, when you select a cell, the frame changes with animation).

So I implemented one CADisplayLink hours that call min mask-update-logic on each screen-frame update (ex: 1/60 second), I remove the frame information cell.layer.presentationLayer() instead of made directly, but the acquired frame of the cell is not accurate, and the animation therefore looks jiggly.

My first suspicion was that my logic took a long execution time, so I measured the runtime of my mask logic, and it was a maximum of about 0.00022 seconds, which is 1/80 of the screen refresh rate.

My second suspicion is that the devices used (CGFloat) lack some precision and cause the misalignment.

what may be the cause of such behavior, or what may be a better approach to achieve gradient effect. All help is highly appreciated.


Source link