【发布时间】:2014-03-20 16:19:05
【问题描述】:
我使用了 Apple 示例应用中的这段代码,并将其调整为我的。我希望 UIImageView gameOverFalling 运行此方法(跌倒和反弹)。它应该与 UIView finalScoreView 发生冲突,如您在第 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;
}
但是,当我运行我的应用程序时,它会返回 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}}
当我将第 2 行的“finalScoreView”替换为“self.view”时,它可以工作,但它会落在整个屏幕的底部。
任何想法我做错了什么?我很想知道,谢谢!
【问题讨论】:
标签: iphone animation view uiview