I used this code from Apple's sample app and adjusted it to mine. I want the UIImageView gameOverFalling
to run this method (fall and kind of bounce). It should collide with the UIView finalScoreView
, as you can see in line 2.
-(void)gameOverFallingMethod{
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:finalScoreView];
UIGravityBehavior *gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[self.gameOverFalling]];
[animator addBehavior:gravityBeahvior];
UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.gameOverFalling]];
// Apple said: "Creates collision boundaries from the bounds of the dynamic animator's
// reference view (self.view)."
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
collisionBehavior.collisionDelegate = self;
[animator addBehavior:collisionBehavior];
self.animator = animator;
}
However when I run my app, it returns a Thread 1: SIGABRT error. In the console:
View item (<UIImageView: 0x10aaa0c70; frame = (15 175; 288 42); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x10aa7e0a0>>) should be a descendant of reference view in <UIDynamicAnimator: 0x10ae17610> Stopped (0.000000s) in <UIView: 0x10aa9e1e0> {{0, 0}, {288, 195}}
It works when I replace 'finalScoreView' on line 2 with 'self.view', but then it falls to the bottom of the whole screen.
Any ideas what I did wrong? I would love to know, thanks!