首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIKit动力"SolveVelocityConstraints“坠机

UIKit动力"SolveVelocityConstraints“坠机
EN

Stack Overflow用户
提问于 2013-11-03 15:05:58
回答 2查看 590关注 0票数 4

在使用UIKit Dynamics时,我一直在崩溃。并不是每次代码运行时都会发生这种情况,但是这种情况经常发生。有人遇到过这个吗?

代码语言:javascript
复制
Assertion failed: (a.x >= 0.0f && a.y >= 0.0f), 
function SolveVelocityConstraints, file 
/SourceCache/PhysicsKit/PhysicsKit-
4.6/PhysicsKit/Box2D/Dynamics/Contacts/b2ContactSolver.cpp, line 422.

这是生成错误的代码。我猜这和碰撞边界有关。

代码语言:javascript
复制
UIDynamicAnimator *animator = 
 [[UIDynamicAnimator alloc] initWithReferenceView:self];

UIGravityBehavior *gravityBehavior = 
 [[UIGravityBehavior alloc] initWithItems:@[self.rewardButton]];
gravityBehavior.gravityDirection = CGVectorMake(0.0, 1.0);
gravityBehavior.magnitude = 1.0f;

UICollisionBehavior* collisionBehavior = 
 [[UICollisionBehavior alloc] initWithItems:@[self.rewardButton, 
                                              self.processingView]];
collisionBehavior.collisionDelegate = self;
UIEdgeInsets insets = UIEdgeInsetsMake(-700, 60, 200, 60);
[collisionBehavior setTranslatesReferenceBoundsIntoBoundaryWithInsets:insets];

UIDynamicItemBehavior* propertiesBehavior = 
 [[UIDynamicItemBehavior alloc] initWithItems:@[self.rewardButton]];
float elasticity = arc4random() % 4 * 0.1 + 0.1f;
propertiesBehavior.elasticity = elasticity;

[animator addBehavior:propertiesBehavior];
[animator addBehavior:gravityBehavior];
[animator addBehavior:collisionBehavior];

self.animator = animator;
EN

回答 2

Stack Overflow用户

发布于 2013-11-27 06:41:08

对我来说似乎可行的一点是为UIDynamicItemBehavior设置了一个非常大的密度值。使用1或2的密度仍然给了我错误,但500似乎没有。就像我说的,它是相当讨厌的,但是,在我非常有限的测试中,它似乎能做到这一点。

代码语言:javascript
复制
UIDynamicItemBehavior *itemBehavior = 
 [[UIDynamicItemBehavior alloc] initWithItems:self.items];
[itemBehavior setDensity:500.0f];
[self.animator itemBehavior];

感谢KillerRhino的评论和Box2D的帖子,他链接到我的这条路,把这个项目的大量内容作为问题进行调查。根据UIDynamicItemBehavior文档,密度和它的大小决定了质量。希望这一解决办法在其他条件/设置下仍然有效。

我认为这个问题只发生在新的A7芯片上(iPhone 5s,iPad Air,iPad Mini Retina)。可能是64位的问题?

票数 1
EN

Stack Overflow用户

发布于 2013-12-13 04:04:30

我也有过同样的破碎机。我通过增加physicsBody对象的质量来解决这个问题。它们真的很小,比如0.05。把他们增加到50人(每件事乘以1,000人),这使破碎机停了下来。当然,你必须改变一些其他性质,使物理效应看起来和增加质量之前一样。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19754357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档