How can I speed up UISnapBehavior?

I can easily make the binding slower by adding a UIDynamicItemBehavior with resistance. However, the default value for resistance is 0.0, which is still too slow for me. Setting the resistance to a negative value has no effect, it seems that it moves with an accuracy of 0.0.

How to speed up UISnapBehavior?

(Here is an example of creating a binding slower ):

UIDynamicItemBehavior *dynamicItemBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[button]];
dynamicItemBehavior.resistance = 50.0; // This makes the snapping SLOWER
UISnapBehavior *snapBehavior = [[UISnapBehavior alloc] initWithItem:button snapToPoint:point];
[self.animator addBehavior:button.dynamicItemBehavior];
[self.animator addBehavior:button.snapBehavior];
+3
source share
1 answer

You can also use UIAttachmentBehaviorto achieve a similar effect, as UISnapBehaviorwith great speed control. For instance:

UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:viewToAnimate attachedToAnchor:viewToAnimate.center];
[self.animator addBehavior:attachment];
attachment.frequency = 20.0;
attachment.damping = 1.0;
attachment.anchorPoint = newPoint;

frequency 1.0 . frequency 0.0 1.0, ( resistance , 1.0 UIDynamicItemBehavior).


, frequency, :

UIDynamicItemBehavior *resistance = [[UIDynamicItemBehavior alloc] initWithItems:@[viewToAnimate]];
resistance.resistance = 100.0;
[self.animator addBehavior:resistance];
+5

All Articles