碰撞行为不起作用

时间:2013-12-27 07:37:32

标签: ios animation collision behavior microsoft-dynamics

我正在尝试UIKit Dynamics,并试图创建一个简单的动画,其中一个球从屏幕边界反弹。

如下面的代码所示,当我添加重力行为时,球似乎按预期离开了屏幕。但是当我添加碰撞行为时,没有任何反应。球保持原样在我最初绘制的屏幕中心。

我还试图通过连续推力选项添加推动行为,但球仍不会移动。

@implementation TAMViewController

UIDynamicAnimator* animator;
UIGravityBehavior* gravity;
UICollisionBehavior* collision;
UIPushBehavior* push;


- (void)viewDidLoad
{
    [super viewDidLoad];

    TAMBouncyView *ballView = [[TAMBouncyView alloc] initWithFrame:CGRectMake(0,0, 
                                self.view.frame.size.width,  
                                self.view.frame.size.height)];

    [self.view addSubview:ballView];

    animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    gravity = [[UIGravityBehavior alloc] initWithItems:@[ballView]];
    [animator addBehavior:gravity];

    collision = [[UICollisionBehavior alloc] initWithItems:@[ballView]];
    [collision setTranslatesReferenceBoundsIntoBoundary:YES];
    [animator addBehavior:collision];

    push = [[UIPushBehavior alloc] initWithItems:@[ballView]    
                                     mode:UIPushBehaviorModeContinuous];
    [animator addBehavior:push];

    // Do any additional setup after loading the view, typically from a nib.
}

0 个答案:

没有答案