I have a cursor object and I want to be able to tell when it intersects an nsbutton, and whether it does continuously for a 3 seconds. My code works except that when the cursor comes near a button, it freezes until it has been three seconds and then logs "Button overlapped for 3 seconds".
NSDate* date;
-(BOOL)checkIfIntersects :(NSButton*)button {
BOOL intersects = CGRectIntersectsRect (cursor.frame,button.frame);
if (intersects) {
date = [NSDate date];
while (intersects) {
if ([date timeIntervalSinceNow] < -1)
{
NSLog(@"Button overlapped for 3 seconds");
break;
}
intersects = CGRectIntersectsRect (cursor.frame,button.frame);
}
}
return NO;
}