Cocoa:关闭菜单前闪烁项目(Cocoa : Blinking item before closing the menu)
单击OSX上的菜单项时,项目在菜单关闭前闪烁一次(关闭时关闭)。
我问自己,我怎么能模仿这种行为? (我使用NSCollectionView重新实现了一个菜单,选项和clic on item都工作)
我试过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];When clicking on a Menu item on OSX, the item blinks (on-off-on-close) once before the menu closes.
I was asking my self how can mimic that behavior ? (I've reimplemented a Menu using NSCollectionView, selection & clic on item both work)
I tried 2 thinks that did not work :
mouseOver = false; [self drawRect:self.bounds]; mouseOver = true; [self drawRect:self.bounds]; [[self window] performSelector:@selector(orderOut:) withObject:nil afterDelay:0.1];and
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];最满意答案
我去找那个解决方案:
-(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]; }I went for that solution :
-(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]; }更多推荐
发布评论