我试图设置一个块的动作属性,但没有工作......任何想法?我知道UIView动画...方法有一个完成块,但不确定UIDynamicAnimations。如何在UIGravityBehavior将其移出屏幕后移除UIView?
编辑:添加代码
[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 01:33:30