Hun*_*apa 3 cocoa-touch objective-c ios uikit-dynamics
通过添加带阻力的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];
Run Code Online (Sandbox Code Playgroud)
您还可以使用a 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;
Run Code Online (Sandbox Code Playgroud)
通过增加到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];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2714 次 |
| 最近记录: |