
A和B俩视图的关系,B贴在A上。
A的代码:若把[super mouseDown:event];
屏蔽,则B里不会执行-mouseDown:
方法。
- (void)mouseDown:(NSEvent *)event
{
[super mouseDown:event];
}
- (void)mouseUp:(NSEvent *)event
{
[super mouseUp:event];
}
//AppKit 里的 NSControl 默认都是不追踪 mouseMove 事件的,增加这个方法用来激活 mouseMove、mouseEnter、mouseExit等事件追踪
@interface IPBorderedView ()
{
NSTrackingArea *trackingArea;
}
@end
@implementation IPBorderedView
- (void)updateTrackingAreas
{
[super updateTrackingAreas];
if (trackingArea){
[self removeTrackingArea:trackingArea];
trackingArea=nil;
}
NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingActiveInKeyWindow;
trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}
网友评论