我可以通过添加带阻力的UIDynamicItemBehavior轻松地使捕捉更慢。但是,阻力的默认值是0.0,这对我来说仍然太慢。将阻力设置为负值没有任何影响,它似乎移动到0.0。
如何让UISnapBehavior更快?
(以下是使捕捉更慢的示例):
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];
答案 0 :(得分:5)
您还可以使用UIAttachmentBehavior
来实现与UISnapBehavior
类似的效果,同时更好地控制速度。例如:
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];