我使用了苹果公司的示例应用程序中的代码,并根据我的需求进行了调整。 我希望UIImageView gameOverFalling
运行这个方法(下落并弹跳)。 正如您在第2行中所看到的那样,它应该与UIView finalScoreView
相撞。
-(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;
}
然而,当我运行我的应用程序时,它返回一个Thread 1:SIGABRT错误。在控制台中:
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}}
如果我将第二行中的'finalScoreView'替换为'self.view',则它可以起作用,但它会掉到整个屏幕的底部。
你有什么想法吗?我很想知道,谢谢!