好的,这是问题所在:
我有一个,NSTextView
然后NSButton
使用以下命令添加了自定义:
[_textView addSubview:button];
然后,在我的NSButton
子类中,我(以及其他NSTrackingArea
东西):
- (void)mouseEntered:(NSEvent *)event{
[[NSCursor arrowCursor] set];
}
- (void)mouseExited:(NSEvent *)theEvent{
[[NSCursor arrowCursor] set];
}
- (void)mouseDown:(NSEvent *)theEvent{
[[NSCursor arrowCursor] set];
}
- (void)mouseUp:(NSEvent *)theEvent{
[[NSCursor arrowCursor] set];
}
但是当我将其悬停时,光标保持不变IBeamCursor
(因为它是NSTextView
)。只有当我按下按钮时,光标才会更新。然后,当我移动鼠标时,仍在按钮内,光标返回到IBeamCursor
。
有关如何执行此操作的任何想法?谢谢!
添加仅跟踪进入/退出事件的跟踪区域似乎不足以实现NSTextView
子视图。文本视图总是以某种方式赢得并设置它 IBeamCursor
。
在子类中添加跟踪区域时,您可以尝试始终启用对鼠标移动事件NSTrackingMouseMoved
的跟踪()NSButton
:
#import "SSWHoverButton.h"
@interface SSWHoverButton()
{
NSTrackingArea* trackingArea;
}
@end
@implementation SSWHoverButton
- (void)mouseMoved:(NSEvent*)theEvent
{
[[NSCursor arrowCursor] set];
}
- (void)updateTrackingAreas
{
if(trackingArea != nil)
{
[self removeTrackingArea:trackingArea];
}
NSTrackingAreaOptions opts = (NSTrackingMouseMoved|NSTrackingActiveAlways);
trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
options:opts
owner:self
userInfo:nil];
[self addTrackingArea:trackingArea];
}
- (void)dealloc
{
[self removeTrackingArea:trackingArea];
}
@end
非常感谢您的回答,但不幸的是它没有用:/
嗨,Pedro,我只是在一个示例Xcode项目中尝试过。在这里像吊饰一样工作(10.8)。您是否使用了我上面发布的子类?如果是这样,您是否实例化了它而不是您自己的?
糟糕,请原谅我!它现在正在工作,还有,我什么都没改变:P非常感谢!