I can easily make the snapping 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 move as fast as 0.0.
我可以很容易地通过添加一个具有抗性的UIDynamicItemBehavior来让它变得更慢。但是,电阻的默认值是0.0,这对我来说还是太慢了。将阻力设置为负值没有任何影响,它的移动速度似乎和0.0一样快。
How can I make the UISnapBehavior faster?
如何使UISnapBehavior更快?
(Here is an example of making the snapping 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];
1 个解决方案
#1
5
You can also use a UIAttachmentBehavior
to achieve a similar affect as UISnapBehavior
, with greater control over speed. For example:
您还可以使用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;
By increasing frequency
to values above 1.0
will make it faster. By decreasing frequency
to values between 0.0
and 1.0
, will make it slower (or by adding resistance
values greater than 1.0
to your UIDynamicItemBehavior
).
通过将频率增加到1.0以上将使其更快。通过将频率降低到0.0到1.0之间的值,将使其变慢(或者通过向UIDynamicItemBehavior添加大于1.0的电阻值)。
If you find it oscillating at that final location when using this frequency
value, add some resistance to the item, too:
如果你在使用这个频率值时发现它在最后的位置震荡,也增加一些对该项目的阻力:
UIDynamicItemBehavior *resistance = [[UIDynamicItemBehavior alloc] initWithItems:@[viewToAnimate]];
resistance.resistance = 100.0;
[self.animator addBehavior:resistance];
#1
5
You can also use a UIAttachmentBehavior
to achieve a similar affect as UISnapBehavior
, with greater control over speed. For example:
您还可以使用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;
By increasing frequency
to values above 1.0
will make it faster. By decreasing frequency
to values between 0.0
and 1.0
, will make it slower (or by adding resistance
values greater than 1.0
to your UIDynamicItemBehavior
).
通过将频率增加到1.0以上将使其更快。通过将频率降低到0.0到1.0之间的值,将使其变慢(或者通过向UIDynamicItemBehavior添加大于1.0的电阻值)。
If you find it oscillating at that final location when using this frequency
value, add some resistance to the item, too:
如果你在使用这个频率值时发现它在最后的位置震荡,也增加一些对该项目的阻力:
UIDynamicItemBehavior *resistance = [[UIDynamicItemBehavior alloc] initWithItems:@[viewToAnimate]];
resistance.resistance = 100.0;
[self.animator addBehavior:resistance];