Re: Best approach for custom button using layers?
Re: Best approach for custom button using layers?
- Subject: Re: Best approach for custom button using layers?
- From: edward taffel <email@hidden>
- Date: Sun, 06 Apr 2014 11:40:15 -0400
i have a number of custom buttons in my app, all derived from NSButton. some do some simple animation (no Core Animation) which i handle in drawRect determined by state. i connect actions in ib, as usual, but with one difference: i handle mouseDown where i change state (open/closed, on/off, etc.), setToolTip & send
[self setNeedsDisplay:YES];
[self sendAction:[self action] to:[self target]];
mouseDown, of course, may be defined once in a base from which you derive—thus, you need only override drawRect in derived classes.
hope this helps,
edward
On Apr 6, 2014, at 3:25 AM, Graham Cox <email@hidden> wrote:
> I want to make some custom buttons to replace the standard checkbox, and maybe others. I also want to make use of Core Animation layers to animate aspects of these.
>
> Looking at the current model of NSControl + NSCell subclasses (in this case NSButton + NSButtonCell), they bring along much baggage. That in itself isn't a problem as such, but the whole design seems to be not such a great fit for a CA layer approach - the cells are supposed to draw when told to by the hosting control, and fitting the layer model into this seems like hard work - at what point does the cell add its layers to the view, for example? Both the control and the cell will need subclassing so that I can make the control a layer-hosting view not a layer-backed one, and there's no telling whether that's going to interfere with anything it does already.
>
> The alternative is just to subclass NSView and bypass the whole NSControl hierarchy. For the things I want to do, which are simple, this is awfully tempting. It has one obvious downside and that is IB support for hooking up actions, which appears to rely on the object being an NSControl.
>
> What's the best advice here? Have others managed to make layer-based controls and what's the best approach? I've created custom NSCell subclasses in the past, but this is the first time I want to make them animatable using layers. I don't think I want to use these controls in matrixes or tables, so there's nothing that absolutely compels me to follow the control + cell model.
>
> --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
_______________________________________________
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