开发者

NSView mouseExited

开发者 https://www.devze.com 2023-02-24 10:35 出处:网络
I have an NSView and basically, even when my mouse doesn\'t leave the defined frame, just moves within it, mouseExited function is called. Is this how is it suppose to be or am I doing something wrong

I have an NSView and basically, even when my mouse doesn't leave the defined frame, just moves within it, mouseExited function is called. Is this how is it suppose to be or am I doing something wrong? There are several subviews of this NSView and it's custom and here's the code for it:

开发者_运维百科
- (id)initWithDelegate:(id)del {
    if (self = [super init]) {
        [del retain];
        delegate = del;
    }
    return self;
}

- (void)dealloc {
    [delegate release];
    [super dealloc];
}

- (void)viewDidMoveToWindow {
    [self addTrackingRect:[self bounds]
                    owner:self
                 userData:nil
             assumeInside:NO];
}

- (void)mouseEntered:(NSEvent *)theEvent {
    [delegate mouseEntered];
}

- (void)mouseExited:(NSEvent *)theEvent {
    NSLog(@"mouse exited");
    [delegate mouseExited];
}

- (void)mouseDown:(NSEvent *)theEvent {
    [delegate mouseDown];
}

- (NSView *)hitTest:(NSPoint)aPoint {
    return self;
}

Thanks.


I figuered it out. After adding a tracking area, i was changing the frame of my view so I needed to recalculate the tracking area. Found this method that will automatically be called whenever tracking area needs to be updated:

- (void)updateTrackingAreas {

Just simply recalculate your tracking area here.

0

精彩评论

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