gpt4 book ai didi

iphone - UIDynamicAnimator - 不能与 UIView 一起使用,但可以与 Self.View 一起使用吗?

转载 作者:行者123 更新时间:2023-12-03 18:43:06 24 4
gpt4 key购买 nike

我使用了 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;
}

但是,当我运行我的应用程序时,它返回线程 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”时,它可以工作,但随后它会落到整个屏幕的底部。

你知道我做错了什么吗?我很想知道,谢谢!

最佳答案

从异常看来,self.gameOverFalling 并不是从 View 层次结构中的 finalScoreView 下降的。请参阅 UIDynamicAnimator class reference 的引用:

To animate views, create an animator with the initWithReferenceView: method. The coordinate system of the reference view serves as the coordinate system for the animator’s behaviors and items. Each dynamic item you associate with this sort of animator must be a UIView object and must descend from the reference view.

关于iphone - UIDynamicAnimator - 不能与 UIView 一起使用,但可以与 Self.View 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21895674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com