我在使用 UIKit Dynamics
时总是遇到崩溃。它不会在每次代码运行时发生,但它经常发生。有人遇到过这个吗?
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.
这是产生错误的代码。我猜测它与碰撞边界有关。
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;
最佳答案
似乎对我有用的一点技巧是为 UIDynamicItemBehavior 设置非常大的密度量。使用 1 或 2 的密度仍然给我错误,但 500 似乎没有。就像我说的,它很老套,但在我非常有限的测试中,它似乎可以解决问题。
UIDynamicItemBehavior *itemBehavior =
[[UIDynamicItemBehavior alloc] initWithItems:self.items];
[itemBehavior setDensity:500.0f];
[self.animator itemBehavior];
感谢 KillerRhino 的评论和他链接的 Box2D 线程引导我走上了这条研究项目质量问题的道路。根据UIDynamicItemBehavior documentation密度及其大小决定了质量。希望此变通办法在其他条件/设置下有效。
我认为这个问题只发生在配备新 A7 芯片的新设备上(iPhone 5s、iPad Air、iPad Mini Retina)。可能是 64 位问题?
关于ios - UIKit 动态 "SolveVelocityConstraints"崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19754357/