我试图在action属性上设置一个块,但没有成功...有什么想法吗?我知道UIView动画。方法有一个完成块,但不确定UIDynamicAnimations。
编辑:添加代码
[self.animator removeAllBehaviors];
UIGravityBehavior *gravityBehaviour = [[UIGravityBehavior alloc] initWithItems:@[self.onscreen]];
gravityBehaviour.gravityDirection = CGVectorMake(0, 10);
gravityBehaviour.action = ^{
if(self.onscreen.frame.origin.y > [UIScreen mainScreen].bounds.size.height)
[self.onscreen removeFromSuperview];
NSLog(@"locations is %f, height is %f", self.onscreen.frame.origin.y, [UIScreen mainScreen].bounds.size.height);
};
[self.animator addBehavior:gravityBehaviour];
UIDynamicItemBehavior *itemBehaviour = [[UIDynamicItemBehavior alloc] initWithItems:@[self.onscreen]];
[itemBehaviour addAngularVelocity:-M_PI_2 forItem:self.onscreen];
[self.animator addBehavior:itemBehaviour];输出反映出,即使在屏幕之外,视图也会继续移动。
发布于 2015-02-08 09:58:28
因此,我通过在if语句中再抛出一个东西来解决这个问题: animator removeAllBehaviors;这似乎起到了作用。
发布于 2016-08-03 18:00:41
let dynamicBehaviour = UIDynamicItemBehavior(items: [randomWord])
weak var weakBehaviour = dynamicBehaviour
weak var weakSelf = self
dynamicBehaviour.action = {
if let currentY = weakBehaviour?.linearVelocityForItem(rndWord).y {
if currentY > CGRectGetMaxY(self.view.frame) / 2 {
weakSelf?.animator?.removeAllBehaviors()
weakSelf?.randomWord?.removeFromSuperview()
}
}
}https://stackoverflow.com/questions/28389494
复制相似问题