Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Miglu

macrumors member
Original poster
Jan 22, 2010
74
0
Adding an NSTrackingArea does not work if I add it from another object than the view that I am adding it to, using this code:
Code:
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:areaRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow) owner:gameView userInfo:nil];
[gameView addTrackingArea: area];
It works if I do the same in gameView, with "gameView" replaced by "self" in the code. What is the problem?
 
What do you mean "does not work"? Are you not getting any mouseEntered or mouseExited calls? How are you calculating areaRect?
 
I am not getting MouseEntered or MouseExited calls.
Code:
    for (float i = 0; i < 5; i++) {
        NSRect areaRect;
        areaRect.origin.x = INDENT*bounds.size.width;
        areaRect.origin.y = (1 - (GAP + LENGTH)*i)*bounds.size.height;
        areaRect.size.width = LENGTH*bounds.size.height;
        areaRect.size.height = LENGTH*bounds.size.height;
        NSTrackingArea *track = [[NSTrackingArea alloc] initWithRect:areaRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow) owner:self userInfo:nil];
        [self addTrackingArea: track];
    }
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.