我创建UIDynamicAnimator
并向UIGravityBehavior
动画师添加重力,但重力不起作用。并在那里显示我的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];
}