This is because your thread is stuck inside the while(intersects)
loop, only exiting after the internal if
statement is satisfied. This will hang your entire thread.
The quickest/easiest solution for you would be to have an interaction flag outside of your function along with your NSDate
.
NSDate* momentIntersectionBegan = nil;
BOOL intersectedPreviously = false;
-(BOOL)checkIfIntersects :(NSButton*)button {
BOOL currentlyIntersects = CGRectIntersectsRect (cursor.frame,button.frame);
if (currentlyIntersects) {
if(intersectedPreviously){
if ([momentIntersectionBegan timeIntervalSinceNow] < -3)
{
NSLog(@"Button overlapped for 3 seconds");
}
}else{
momentIntersected = [NSDate date];
}
intersectedPreviously = true;
}else{
intersectedPreviously = false;
}
return NO;
}