Cocoa:关闭菜单前闪烁项目(Cocoa : Blinking item before closing the menu)

编程入门 行业动态 更新时间:2024-10-13 06:20:05
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]; }

更多推荐

本文发布于:2023-08-05 20:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:菜单   项目   Cocoa   Blinking   menu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!