iOS UIDynamicAnimator实例对象为什么不作为property出现的时候不好使??
- (void)shake
{
if (!self.animator) {
self.animator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
}
[self.animator removeAllBehaviors];
CGPoint newPos = CGPointMake(arc4random()%320, arc4random()%568);
UISnapBehavior *snap = [[UISnapBehavior alloc]initWithItem:_btn snapToPoint: newPos];
snap.damping = 0.3;
[self.animator addBehavior:snap];
// UIDynamicAnimator *animator = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
//
// [animator removeAllBehaviors];
//
// CGPoint newPos = CGPointMake(arc4random()%320, arc4random()%568);
// UISnapBehavior *snap = [[UISnapBehavior alloc]initWithItem:_btn snapToPoint: newPos];
// snap.damping = 0.3;
// [animator addBehavior:snap];
}
注释部分的代码是不作为property出现的,上下两段代码除了一个是property一个不是其它的都一毛一样,为什么只有当animator作为property的时候这个add进去的snap动画才生效呢??看了官方文档也没找到这方面的解释,而且之前忘记是用什么其它的东西也是遇到了这种情况。跪求大神给解释一下ORZ
爱国者之枪
9 years, 6 months ago