0

在 OSX 上单击菜单项时,该项目会在菜单关闭前闪烁一次(on-off-on-close)。

我在问自己如何模仿这种行为?(我已经使用 NSCollectionView 重新实现了一个菜单,选择和单击项目都可以)

我试过 2 认为没有用:

mouseOver = false;
[self drawRect:self.bounds];
mouseOver = true;
[self drawRect:self.bounds];

[[self window] performSelector:@selector(orderOut:) withObject:nil afterDelay:0.1];

mouseOver = false;
[self setNeedsDisplayInRect:self.bounds];
[self needsDisplay];
mouseOver = true;
[self setNeedsDisplayInRect:self.bounds];
[self needsDisplay];

[[self window] performSelector:@selector(orderOut:) withObject:nil afterDelay:0.1];
4

1 回答 1

0

我去了那个解决方案:

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

    [self performSelector:@selector(blinkItemOnce:) withObject:[NSNumber numberWithBool:NO] afterDelay:0.0];
    [self performSelector:@selector(blinkItemOnce:) withObject:[NSNumber numberWithBool:YES] afterDelay:0.05];
    [[self window] performSelector:@selector(orderOut:) withObject:nil afterDelay:0.15];
}

-(void) blinkItemOnce:(NSNumber*) b {
    mouseOver = [b boolValue];
    [self setNeedsDisplayInRect:self.bounds];
    [self setNeedsDisplay:YES];
}
于 2013-01-26T13:57:38.283 回答