Doodles... Open GL?
I am making an app where one function is the ability to place pre-made doodles on the page, They will have the ability to zoom the doodles in and out and place them where they wish. This is all for the iPad. Do I need to use open GL for this or i开发者_如何学运维s there a better / easier way? (New to iOS programming)
You should be able to achieve this using CALayer
s. You will need to need to add the QuartzCore
framework for this to work. The idea would be to represent each doodle as a single CALayer
. If your doodles are images, you can use the contents
property to assign the doodle to the layer. You will need to assign a CGImageRef
object which you can easily retrieve using CGImage
property of a UIImage
object.
You will need a view which will be your drawing board. Since you want to be able to move and alter the sizes of the doodles, you will have to attach a UIPanGestureRecognizer
object for moving the layers and a UIPinchGestureRecognizer
to zoom the doodles in and out. Since the recognizers can only be attached to a view and not layers, the non-trivial part when the gesture handlers are called will be identify which sublayer of the view are they manipulating. You can get the touches for the gestures using locationInView:
for the pan gesture and locationOfTouch:inView:
for the pinch gesture with the view argument being the view that the gesture is being done on which can be retrieved using gesture.view
. Once you identify the layer in focus, you can use translationInView:
for pan gesture to move the layer and use scale
property of the pinch gesture to transform the layer.
While CALayer
objects are lightweight objects, you could face problems when there are just too many of them. So stress test your application. Another roadblock is that images are usually memory hogs so you might not be able to get a lot of doodles in.
精彩评论