TeehanLax / UICollectionView-Spring-Demo

A demonstration of UICollectionView and UIKit Dynamics
MIT License
471 stars 71 forks source link

residual oscillation #24

Open allen8300 opened 7 years ago

allen8300 commented 7 years ago

Hi, man, thanks so much for your hard work. But in the native Messages app, there is no oscillation, everything is smooth. In the demo app, there is a residual oscillation. Can you please solve it? So that it works more smoothly?

iTofu commented 6 years ago

Make sure item.center is returning X and Y values that are floats with NO DECIMALS. https://stackoverflow.com/a/24564539/6137672

In that case:

// Line 87:
UIAttachmentBehavior *springBehaviour = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:center];
// ->
center.x = (int)center.x;
center.y = (int)center.y;
UIAttachmentBehavior *springBehaviour = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:center];

// Line 205:
UIAttachmentBehavior *springBehaviour = [[UIAttachmentBehavior alloc] initWithItem:attributes attachedToAnchor:attributes.center];
// ->
CGPoint center = attributes.center;
center.x = (int)center.x;
center.y = (int)center.y;
UIAttachmentBehavior *springBehaviour = [[UIAttachmentBehavior alloc] initWithItem:attributes attachedToAnchor:center];