[英]iOS: UIDynamics Push Behavior
I have created this little animation using UIDynamics
- Push Behavior
. 我已经使用
UIDynamics
- Push Behavior
创建了这个小动画。
What I did was: 我所做的是:
I created a simple UIPushBehavior
like so: 我创建了一个简单的
UIPushBehavior
如下所示:
self.pushBehavior = [[UIPushBehavior alloc] initWithItems:@[self.littleJumpy] mode:UIPushBehaviorModeInstantaneous];
littleJumpy is just a UIView
with size: {20, 20}
that is added to the current view. littleJumpy只是一个大小为
{20, 20}
的UIView
,已添加到当前视图中。
[animator addBehavior:self.pushBehavior];
Then afterward I would set the magnitude
and then subsequently set active = YES;
然后,我将设置
magnitude
,然后将其设置为active = YES;
The above is within a method. 以上是一种方法。
It is working flawlessly. 它工作正常。
At certain point in time I would set this push behavior's active
state to NO
. 在某个时间点,我会将此推送行为的
active
状态设置为NO
。 And afterward I would set it again to YES
. 然后,我将其再次设置为
YES
。
The problem arises with this. 由此产生问题。 I realized that once a push behavior's active state is set to
NO
, it cannot be revived again by setting it to YES
. 我意识到,一旦将推送行为的活动状态设置为
NO
,就无法通过将其设置为YES
来再次恢复。
As a result, I would need to alloc and configure a new push behavior and add it to the animator
all over again. 结果,我将需要分配和配置新的推送行为,并将其重新添加到
animator
。
What worries me is memory issue, if we need to alloc
and init
the push behavior again and again after setting its active
state to NO
. 我担心的是内存的问题,如果我们需要
alloc
和init
其设置后连连推行为active
状态NO
。
For a few animations, it shouldn't hurt, but if someone wanted to create a continuous movement and during the period the behavior's active
state is set to NO
and cannot simply be revived by setting it again to YES
, in which case a new alloc
+ init
needs to be performed again and then added to the animator over and over again. 对于少数动画,它不应该受到伤害,但如果有人想创建一个连续运动,在此期间的行为的
active
状态设置为NO
,不能简单地再次将其设定为复兴YES
,在这种情况下,一个新的alloc
+ init
需要再次执行,然后一遍又一遍地添加到动画制作器中。
Is this the normal behavior or am I missing something here? 这是正常现象,还是我在这里错过了一些东西?
Happy Holidays. 节日快乐。
This is an old question. 这是一个老问题。
But after months of experimenting, I came to a conclusion that once the active
state is set to NO
, I would have to re- alloc
and re- init
the behavior again, in order to re-use the behavior. 但实验的个月后,我来到了,一旦一个结论
active
状态设置为NO
,我将不得不重新alloc
和重新init
一次的行为,以便重新使用的行为。
Other words, setting it again to YES
from NO
does not re-activate the behavior. 换句话说,将其再次从
NO
设置为YES
不会重新激活该行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.