0

In my app, I have small views that can be moved around by dragging them. When the user begins dragging on one of the small views, it stays in place, but is 'stretched' for a certain distance (~200 points). After the distance is exceeded, then the small view should perform a 'snap' effect to the user's finger. The whole animation is best described as a rubber band breaking.

So far, I've implemented the snap effect like so:

UISnapBehavior *snapBehavior = [[UISnapBehavior alloc] initWithItem:iconView snapToPoint:[[touches anyObject] locationInView:self.view]];
[self.snapAnimator addBehavior:snapBehavior];

The problem is, if the user continues moving their finger while the snap animation is being performed, the view continues to move towards the point where the finger was when the effect began.

Is there any way to update UISnapBehavior's destination when touches are moved?

eswick
  • 519
  • 4
  • 16

2 Answers2

1

No, there isn't. Snap behavior is extremely simple: it just snaps to the point you tell it, right then. That's all it does. One behavior, one point, one item, one snap.

You would need, therefore, to remove the snap behavior and substitute a different snap behavior with a different point. Or use a different kind of behavior, one where you can move the target point as the user's finger moves (such as UIAttachmentBehavior).

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

In iOS 9 and above, you can. There is now:

@property (nonatomic, assign) CGPoint snapPoint NS_AVAILABLE_IOS(9_0);

It works as expected.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195