Re: UI to allow user to scale and crop image within a circle
Re: UI to allow user to scale and crop image within a circle
- Subject: Re: UI to allow user to scale and crop image within a circle
- From: Graham Cox <email@hidden>
- Date: Thu, 25 Feb 2016 08:44:04 +1100
> On 24 Feb 2016, at 11:08 PM, Charles Jenkins <email@hidden> wrote:
>
> My guess is, you do this by adding a mask layer; but you probably don’t redraw the mask in drawRect(), hm? It should never need to be refreshed unless the bounds change.
Can you not just use a clipping path? They’re usually much easier to set up especially for simple cases like this than a mask layer.
e.g. the simplest way I can think of drawing this is a) draw your image at the correct size and position, b) form a clipping path from the bounds rect plus the desired circle, setting the winding rule if necessary so that the path includes all of the area of your view EXCEPT the circle. c) paint over the entire view in a solid colour (black I think you said). The clipping path ensures that you won’t paint over the circular aperture that shows the image.
> Assuming I can figure out how to make a mask layer, what is the correct way to monitor for a bounds change in order to recreate the mask?
Override -setFrame:, call super then do what you need to do.
However, if you use a clipping path, you can just create this on the fly as part of -drawRect: and so it’ll always be correct, and you won’t need to do this. There’s no reason to cache this path unless it’s really complex and expensive. Hint: it’s not, it’s a circle.
—Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden