Layers can not receive mouse events themselves. You would have to do the event handling in the view or view controller containing the layer.
If a mouseDragged: event originates on a layer (see -[CALayer hitTest:] and -[CALayer containsPoint:] to test this), adjust the layer's position accordingly. You will probably want to disable implicit animations to have the layer follow the mouse pointer immediately (rather than lagging a little behind because of the animation of the position property):
I tried creating a window through code and adding the CALayer to it, but I don't get why it's not showing.
Window is linked to a big window, with a semi-transparent (black filled) window that is resized to fill the screen.
I've made the window draggable, but why isn't the CALayer in the window showing?
Layers can not receive mouse events themselves. You would have to do the event handling in the view or view controller containing the layer.
If a
mouseDragged:
event originates on a layer (see-[CALayer hitTest:]
and-[CALayer containsPoint:]
to test this), adjust the layer'sposition
accordingly. You will probably want to disable implicit animations to have the layer follow the mouse pointer immediately (rather than lagging a little behind because of the animation of the position property):