我使用Apple的示例應用程序中的這段代碼,並將其調整爲我的。我想UIImageView gameOverFalling
運行此方法(秋季和反彈的種類)。它應該與UIView的finalScoreView
碰撞,你可以在第2行UIDynamicAnimator - 不會與UIView一起使用,但會與Self.View一起使用?
-(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;
}
然而,當我跑我的應用程序,它返回一個線程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」 2號線,但隨後下降到整個屏幕的底部。
任何想法我做錯了什麼?我很想知道,謝謝!
它可以解決您的問題! – Fabio