开发者

Is CGLayer a good solution?

I want to add a bit of functionality to my App, and I think that using a CGLayer is the best way of doing it, but have never done any Quartz drawing before (other than some basic tutorials).

My intention is to show a full view of an image that my App will draw (basic geometric shapes based on parameters) in th开发者_高级运维e top half of a view, and show a zoomed in portion of that image in the bottom quarter of the view based on where the user has touched the top image. I want the zoomed in portion to show in a high resolution, so am thinking that I should draw the image onto, say, a 640 x 640 CGLayer, then draw that full layer in the top 320 x 320 half of the view (so scaled down to fit), and the relevant portion touched by the user in the bottom left 160 x 160 of the view, but unscaled, so you'd see a quarter of the main image.

When the user moves their finger around the main view, the portion view in the bottom left would be redrawn from the CGLayer, so no new image rendering is taking place, just CGLayer drawing.

Can anyone see any problem with this approach that my inexperienced brain may have missed?

Ta, Jools.


Look at CALayer and it's contentsRect parameter. It will give you a fairly simple way to do exactly what you're wanting. You can copy the contents of your image view's layer to your zoomed view layer like this:

[[zoomView layer] setContents:[[tapImageView layer] contents]];

Then you set the contentsRect like this:

[[zoomView layer] setContentsRect:CGRectMake(x, y, 0.25, 0.25)];

You would calculate x and y and call this in touchesMoved. Width and height which are set to 0.25 in this code represent what percentage of the image will show in the zoomed view.

Let me know if you need clarification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜