如何在UIGravityBehavior将其移出屏幕后删除UIView?

时间:2015-02-08 01:16:05

标签: ios objective-c uiview core-animation uiviewanimation

我试图在动作属性上设置一个块,但那不起作用......任何想法?我知道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];

输出反映出,即使在屏幕外,视图也会继续移动。

2 个答案:

答案 0 :(得分:0)

所以我通过在if语句中再抛出一个东西来解决它:[animator removeAllBehaviors];这似乎可以解决问题。

答案 1 :(得分:0)

  #id span:hover{
   color: red;
  }