HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UIKit Dynamics“SolveVelocityConstraints”崩溃大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用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.就像我说的那样,它非常hacky但是,在我非常有限的测试中,似乎可以做到这一点.

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 Dynamics“SolveVelocityConstraints”崩溃全部内容,希望文章能够帮你解决ios – UIKit Dynamics“SolveVelocityConstraints”崩溃所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。