我有一个 UIVIew
(容器)和另一个 UIView
(框)框 View 位于 ContainerView
内.当一个 UIButton
按下我希望框 View 从屏幕底部下拉,并在左侧 10px 处反弹;然后一旦弹跳停止,我仍然希望该框显示 10px。这是来自另一个 question 的一些示例代码:
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self]; //self is the container
UIGravityBehavior* gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[box]];
[animator addBehavior:gravityBehavior];
UICollisionBehavior* collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[reportBar.bar]];
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
[animator addBehavior:collisionBehavior];
UIDynamicItemBehavior *elasticityBehavior =
[[UIDynamicItemBehavior alloc] initWithItems:@[box]];
elasticityBehavior.elasticity = 0.7f;
[animator addBehavior:elasticityBehavior];
代码在应该运行的时候运行,但盒子没有掉下来。
![example of layout](https://i.sstatic.net/B4dq0.png)
编辑1:
编辑2:
最佳答案
尝试制作动画师属性,
@property UIDynamicAnimator *animator;
然后是你的代码,
_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self];
...
关于IOS UIView弹跳动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23903054/