> On Feb 24, 2016, at 1:44 PM, Graham Cox <graham....@bigpond.com> wrote:
> 
> 
>> On 24 Feb 2016, at 11:08 PM, Charles Jenkins <cejw...@gmail.com> 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.

-layoutSubviews would be better, as in general if you need to override 
-setFrame: for something, you also need to override -setCenter: and 
-setBounds:. If you need to ensure animation works, you can call 
-layoutIfNeeded inside of your animation block.

But since your drawing something, a clipping view isn’t necessary – you can 
just clip your drawing.

> 
> 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
> 
> 

--
David Duncan


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to