How to avoid dynamics deformation using UIDynamicAnimator

I have a simple tetris-like app where I am dropping square colored labels from the top of the view and they pile up once they collide with the bottom border of the window.

I am using the iOS dynamics framework to simulate the gravity and the collision. I have 2 questions:

  • How can I eliminate completely the bouncing effect when the blocs collide with the bottom border? I have tried setting the elasticity of the collision behaviour to 0 ( the documentation say that this implies no bouncing at all) but the blocs still bounce a bit. So I guess it is a bug in the documentation at least. can anybody confirm this before someone will suggest to try other workarounds?

    Another technique I have tried are to set a very high resistance when the object starts the collision and resetting it to low resistance when the collision ends. The problem with this approach is that this behaviour which is generic for all the blocks, would cause the other falling blocks to be affected ( and slowed down) every time there is a collision happening at the bottom

  • the second question is about how can I stop the animation engine to squeeze the blocks while the pile up ( simulating the real-world effect of gravity over non completely rigid bodies) In my app I can clearly see that the blocks are not aligned because they get squeezed up by the weight of the blocks above.

    How can I avoid this behaviour? I have tried to set the density to 1 and the elasticity to 0 without luck.

    I have also noticed that some blocks at the bottom have the y coordinate = 481 which means that they have been pushed out of their parent view. How is this possible given that the bottom is considered as a collision boundary?


  • To eliminate bouncing effect, you need to add a UIDynamicItemBehavior to your animator. And set the property "elasticity" on the UIDynamicItemBehavior to 0. You can also set the "resistance" property on your UIDynamicItemBehavior to 1 or the max, CGFLOAT_MAX.
  • 链接地址: http://www.djcxy.com/p/96786.html

    上一篇: 视图通过边界

    下一篇: 如何使用UIDynamicAnimator避免动态变形