在使用 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;
Assertion
失败,但事实并非如此。我想分享一下。 - kvn