Search code examples
objective-ccocoa-touchipaduiview

Movable UIViews, like Tangram


In my iPad application, there is one main view. It contains various views which have different sizes and different images (tetragons, but not rectangles).


(source: idzr.org)

The grey lines represent the frames, the red lines represent the outline of the image.

It is a bit like Tangram, but more complicated since the tetragons are not rectangles.

The views can be moved and rotated, but the red tetragons should not touch one another, and not overlay one another. If the corners of the tetragons are known, what is the best way to implement this?


Solution

  • Apple has an example of how to handle this: http://developer.apple.com/library/ios/#samplecode/Touches/Introduction/Intro.html

    Basically, each of your shapes will be a UIView subclass and you'll just need to respond to the proper touch events to move and rotate them accordingly. Yours will just be slightly more complicated because your shapes will have to check to make sure they're not going to overlap another shape when it moves/rotates.