gpt4 book ai didi

macos - 单击 NSBezierPath

转载 作者:行者123 更新时间:2023-12-03 17:53:20 27 4
gpt4 key购买 nike

我正在 NSImageView 上绘制一条 NSBezierPath 线。我正在创建 NSBezierPath 对象,设置 moveToPoint,设置 lineToPoint,设置 setLineWidth: ,然后在 drawRect 中我的 NSImageView 子类我正在调用 [myNSBezierPath stroke]。这一切都按照我想要的方式工作,但我似乎无法使用 containsPoint: 方法...我尝试实现

if([myNSBezierPath containsPoint:[theEvent locationInWindow]]{
//do something
}

在我的 NSImageView 子类的 -(void)mouseUp:(NSEvent*)theEvent 中,但它永远没有反应,我确信我正在点击那条线......我做错了什么吗?我只需要检测 NSBezierPath 是否被单击。

干杯。

最佳答案

确保将鼠标单击位置转换为 ImageView 子类的坐标系,而不是窗口的坐标系(除非它们相同)。您的贝塞尔路径不知道它所绘制的偏移量,因此在执行 HitTest 时必须考虑到这一点。

此外,来自containsPoint:文档:

This method checks the point against the path itself and the area it encloses. When determining hits in the enclosed area, this method uses the non-zero winding rule (NSNonZeroWindingRule). It does not take into account the line width used to stroke the path.

强调我的。

关于macos - 单击 NSBezierPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18555380/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com