Mac开发,实现移动鼠标到指定区域显示提示
// 設置監聽
[self.itemButton addTrackingArea:[[NSTrackingArea alloc] initWithRect:self.bounds options:NSTrackingActiveAlways|NSTrackingInVisibleRect|NSTrackingMouseEnteredAndExited owner:self userInfo:nil]];
?
- (void)mouseEntered:(NSEvent *)event
{
? ? [super mouseEntered:event];
? ? _theMenu = [[NSMenu alloc] initWithTitle:@""];
? ? NSMenuItem *item?= [[NSMenuItem alloc]init];
? ? item.title = @"你好啊";
? ? ?[_theMenu addItem:item3];
?? ? [NSMenu popUpContextMenu:_theMenu withEvent:event forView:self.itemButton];
}
?
- (void)mouseExited:(NSEvent *)event
{
? ? [super mouseExited:event];
? ? [_theMenu removeAllItems];
? ? _theMenu = nil;
}
總結
以上是生活随笔為你收集整理的Mac开发,实现移动鼠标到指定区域显示提示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何学好人力资源管理?方法及书籍推荐
- 下一篇: python迭代器什么时候用_pytho