I have a class called DropitBehavior
, which is inherited from UIDynamicBehavior
. And there are two properties in my UIViewController
.
@property (strong, nonatomic) UIDynamicAnimator *animator;
@property (strong, nonatomic) DropitBehavior *dropitBehavior;
The lazy initializers are defined below. And the animation runs correctly.
- (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;
}
But if I call addBehavior
in animator
initializer, there will be no animation at all. As far as I understand, the animation should run in both ways. What's wrong with the second way?