开发者

Getting a borderless window to receive mouseMoved events (Cocoa OSX)

开发者 https://www.devze.com 2022-12-24 12:55 出处:网络
I have a little popup window used for selecting images sorted by groups, and I would like to add a selection box around whatever image is being hovered over.I am trying to this by overriding the mouse

I have a little popup window used for selecting images sorted by groups, and I would like to add a selection box around whatever image is being hovered over. I am trying to this by overriding the mouseMoved event for the window but it seems that a window that has a border-less style mask r开发者_StackOverfloweceives no mouseMoved events even if you have set setAcceptsMouseMoved events to YES. Is there anyway to make a borderless window receive this events?


You need to allow the window to become the key window. By default, borderless windows cannot become key. Subclass NSWindow and override -canBecomeKeyWindow:

- (BOOL)canBecomeKeyWindow
{
    return YES;
}

Aternatively, you can use an NSTrackingArea to do your mouse tracking, which may be easier/better anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号