0

So I'm looking into UIKit Dynamics and the one problem I have run into is if I want to create a UIView with a custom drawRect: (for instance let's say I want to draw a triangle), there seems to be no way to specify the path of the UIView (or rather the UIDynamicItem) to be used for a UICollisionBehavior.

My goal really is to have polygons on the screen that collide with one another exactly how one would expect.

I came up with a solution of stitching multiple views together but this seems like overkill for what I want.

Is there some easy way to do this, or do I really have to stitch views together?

Dan

DanZimm
  • 2,528
  • 2
  • 19
  • 27

2 Answers2

2

Watch the WWDC 2013 videos on this topic. They are very clear: for the sake of efficiency and speed, only the (rectangular) bounds of the view matter during collisions.

EDIT In iOS 9, a dynamic item can have a customized collision boundary. You can have a rectangle dictated by the frame, an ellipse dictated by the frame, or a custom shape — a convex counterclockwise simple closed UIBezierPath. The relevant properties, collisionBoundsType and (for a custom shape) collisionBoundingPath, are read-only, so you will have to subclass in order to set them.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I just finished watching the first video on this and I don't recall them saying that, but I still have the second video (advanced dynamics) to watch, so I presume it's in there. I suppose I shall get to stitching! – DanZimm Feb 24 '14 at 23:03
  • iOS 9 has added this ability – Wyetro Oct 07 '15 at 02:31
0

If you really want to collide polygons, you might consider SpriteKit and its physics engine (it seems to share a lot in common with UIDynamics). It can mix with UIKit, although maybe not as smoothly as you'd like.

jsd
  • 7,673
  • 5
  • 27
  • 47