我使用Apple的示例应用程序中的代码并将其调整为我的.我想让UIImageView gameOverFalling运行这个方法(跌倒和反弹).它应该与UIView相冲突finalScoreView,正如你在第2行中看到的那样.
-(void)gameOverFallingMethod{
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:finalScoreView];
UIGravityBehavior *gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[self.gameOverFalling]];
[animator addBehavior:gravityBeahvior];
UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.gameOverFalling]];
// Apple said: "Creates collision boundaries from the bounds of the dynamic animator's
// reference view (self.view)."
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
collisionBehavior.collisionDelegate = self;
[animator addBehavior:collisionBehavior];
self.animator = animator;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的应用程序时,它返回一个线程1:SIGABRT错误.在控制台中:
Run Code Online (Sandbox Code Playgroud)View item (<UIImageView: 0x10aaa0c70; frame = (15 175; 288 42); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10aa7e0a0>>) should be a descendant …
假设我有一个动画师将视图从 移动(0, 0)到(-120, 0):
let frameAnimator = UIViewPropertyAnimator(duration: duration, dampingRatio: 0.8)
animator.addAnimations {
switch state:
case .normal: view.frame.origin.x = 0
case .swiped: view.frame.origin.x = -120
}
}
Run Code Online (Sandbox Code Playgroud)
我将它与 一起使用UIPanGestureRecognizer,这样我就可以随着手指的移动不断调整视图的大小。
当我想在动画开始或结束时添加某种弹跳效果时,就会出现问题。不仅仅是阻尼比,还有弹跳效果。最简单的想象方法是 的“滑动删除”功能UITableViewCell,您可以将“删除”按钮拖动到超出其实际宽度,然后它会弹回来。
实际上,我想要实现的是在段fractionComplete之外设置属性的方法[0, 1],因此当分数为 时1.2,偏移量将变为144而不是其最大值 120。
现在 的最大值fractionComplete正是1。
以下是一些可视化此问题的示例:
编辑(1 月 19 日):
抱歉我的回复迟了。以下是一些说明:
我不使用UIView.animate(...),而是UIViewPropertyAnimator出于一个非常具体的原因使用:它为我处理所有的计时、曲线和速度。
例如,您将视图拖动到一半。这意味着剩余部分的持续时间应比总持续时间短两倍。或者,如果您拖动了 99% 的距离,它应该几乎立即完成剩余部分。
作为补充,UIViewPropertyAnimator具有诸如暂停(当用户再次开始拖动时)或反向(当用户开始向左拖动,但之后他改变主意并将手指移到右侧时)等功能,我也受益于。
所有这些对于简单的 UIView 动画来说是不可用的,或者最多需要大量的努力。它只能进行简单的转换,但事实并非如此。
这就是为什么我 …
animation bounce uipangesturerecognizer swift uiviewpropertyanimator
我正在尝试为下面的动画添加一个反弹效果.这是我的代码:
[UIView animateWithDuration:1.0
delay:.0
usingSpringWithDamping:0.5
initialSpringVelocity:2.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
// Coming from a value of CGAffineTransformMakeScale(0.001, 1.0)
self.myView.transform = CGAffineTransformMakeScale(1.0, 1.0);
}completion:nil
];
Run Code Online (Sandbox Code Playgroud)
它无法正常工作.它在动画结束时变宽,然后恢复正常.我希望宽度反弹到小于1.0的值,不超过1.0.