我有一個遊標對象,我希望能夠告訴它什麼時候與nsbutton相交,以及它是否連續3秒。我的代碼工作除了當光標靠近一個按鈕,它凍結,直到它已經三秒鐘,然後記錄「按鈕重疊3秒」。檢查nsbutton是否相交了一定的秒數
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;
}
'NSTrackingRect' –