custom shaped tracking area in cocoa

给你一囗甜甜゛ 提交于 2019-12-23 03:28:05

问题


How to create a custom shaped tracking area in cocoa ? In cocoa I could only find rectangles as tracking area.

Carbon provided this functionality through HIViewNewTrackingArea , through which any HIShapeRef could be registered as a tracking area.Do we have something similar to this in cocoa ?

I have a complex shape in which I want to change mouse cursors at different regions.

One approach I tried was making a big tracking rectangle covering the whole area, and then changing cursor using mouseMoved events.

Could you suggest any other way to do it.

It would have been easier if there was a similar api like HIViewNewTrackingArea in cocoa.

Thanks.


回答1:


Tracking areas are only rectangular in the Cocoa frameworks. You could cover your entire area, then create an NSBezierPath (which you keep around but do not stroke or fill) and ask it if the point is inside it via -containsPoint:.

The tracking area "activates" mouse tracking while the path provides your custom-shaped hit detection mechanism.



来源:https://stackoverflow.com/questions/4459262/custom-shaped-tracking-area-in-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!