【发布时间】:2015-04-07 23:53:47
【问题描述】:
我试图在 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];
输出反映了即使在屏幕外,视图仍会继续移动。
【问题讨论】:
-
在行为的 action 属性上设置一个块是正确的做法。请在此处发布您的代码。
标签: ios objective-c uiview core-animation uiviewanimation