Christian J. B.
Christian J. B.

Reputation: 501

Adding a NSButton to a CALayer in OS X Cocoa

I have a layer hosting view containing a CAlayer, displaying in this case a nice blue opaque rectangle. What I want to do is to add a NSButton on top of the layer, so that it sits above and moves with the blue rectangle when it is animated.

My attempt so far is as follows:

in @interface

IBOutlet NSButton* firstButton;

in @implementation

[layer addSublayer:[firstButton layer]];
firstButton.layer.position=NSMakePoint(0, 80.);

This successfully moves the location of the button on screen, but it doesn't move the 'hit target' of the button.

According to the similar question asked here on Apple Mailing Lists the solution seems to be to move the NSButton with a setFrameOrigin: on the button. This doesn't seem to work for me as it changes the position of the displayed button as well as the 'hit target'. I can't seem to move the hit target independently.

Alternatively: Am I going about this all the wrong way? Is there a better way of doing this?

Upvotes: 0

Views: 753

Answers (1)

sudo rm -rf
sudo rm -rf

Reputation: 29524

Unfortunately you cannot move buttons (including the hit target) by manipulating their layers. This is highly unfortunate, but you're going to have to use the animator proxy on the frame of the button itself, and not try to modify the layer directly.

Upvotes: 1

Related Questions