我有一个名为 的类DropitBehavior
,它继承自UIDynamicBehavior
. 我的UIViewController
.
@property (strong, nonatomic) UIDynamicAnimator *animator;
@property (strong, nonatomic) DropitBehavior *dropitBehavior;
惰性初始化器定义如下。并且动画运行正常。
- (UIDynamicAnimator *)animator
{
if (!_animator) {
_animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.gameView];
//[_animator addBehavior:self.dropitBehavior];
}
return _animator;
}
- (DropitBehavior *)dropitBehavior
{
if (!_dropitBehavior) {
_dropitBehavior = [[DropitBehavior alloc] init];
[self.animator addBehavior:_dropitBehavior];
}
return _dropitBehavior;
}
但是如果我调用初始化程序addBehavior
,animator
根本不会有动画。据我了解,动画应该以两种方式运行。第二种方式有什么问题?