通过添加一个具有阻力的,我可以轻松地使抓取的慢一些。但是,阻力的默认值是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];发布于 2014-03-03 07:11:30
您还可以使用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之间的值,会使其变慢(或者通过向UIDynamicItemBehavior中添加大于1.0的resistance值)。
如果在使用此frequency值时,发现它在最终位置振荡,也会对项目添加一些阻力:
UIDynamicItemBehavior *resistance = [[UIDynamicItemBehavior alloc] initWithItems:@[viewToAnimate]];
resistance.resistance = 100.0;
[self.animator addBehavior:resistance];https://stackoverflow.com/questions/21624728
复制相似问题