为什么我的 UIGravityBehavior 不工作

why my UIGravityBehavior isn't working

我创建了 UIDynamicAnimatorUIGravityBehavior 为动画师添加了引力,但引力不起作用。并显示我的 dropView。

-(UIDynamicAnimator *)animaotr
{
    if(!_animator)
    {
        _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.gameView];
    }
    return _animator;
}
-(UIGravityBehavior *)gravity
{
    if(!_gravity)
    {
        _gravity = [[UIGravityBehavior alloc] init];
        _gravity.magnitude = 1;
        [self.animator addBehavior:_gravity];
    }
    return _gravity;
}

-(void)drop{
CGRect frame;
frame.origin = CGPointZero;
frame.size = DROP_SIZE;
int x = (arc4random()%(int)self.gameView.bounds.size.width) / DROP_SIZE.width;
frame.origin.x = x * DROP_SIZE.width;

UIView *dropView = [[UIView alloc] initWithFrame:frame];
dropView.backgroundColor = [self randomColor];
[self.gameView addSubview:dropView];
[self.gravity addItem:dropView];

}

问题是这个声明:

-(UIDynamicAnimator *)animaotr {

该方法与名称 self.animator 不匹配,因此不会被调用,因此您的重力行为不会添加到任何动画器中。