gpt4 book ai didi

cocoa - NSPopover 未出现

转载 作者:行者123 更新时间:2023-12-03 16:29:07 25 4
gpt4 key购买 nike

我真的希望我能更具体,但不幸的是,我不能。所有适当的对象都是非零的,并且所有适当的方法调用都(大概)成功完成,但我的 NSPopover 从未出现。也没有调用任何委托(delegate)方法。

// ivars
NSPopover *tagPopover;
NSViewController *tagPopoverViewController;

// in method to display popover
tagPopover = [[NSPopover alloc] init];
[tagPopover setBehavior: NSPopoverBehaviorApplicationDefined];
[tagPopover setDelegate: self];
tagPopoverViewController = [[MYViewController alloc] initWithNibName: @"MYViewController" bundle: nil];
[tagPopover setContentViewController: tagPopoverViewController];
[tagPopover setContentSize: tagPopoverViewController.view.frame.size];

[tagPopover showRelativeToRect: NSMakeRect(700, 400, 5, 5) // Screen coordinates
ofView: [[NSApp keyWindow] contentView]
preferredEdge: NSMinYEdge];

最佳答案

原来坐标系是错误的:

NSRect theRect = [[NSApp keyWindow] convertRectFromScreen: NSMakeRect(700, 400, 5, 5)];
[tagPopover showRelativeToRect: theRect // Window Coordinates
ofView: [[NSApp keyWindow] contentView]
preferredEdge: NSMinYEdge];

需要先将其转换为窗口坐标系。

关于cocoa - NSPopover 未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11495082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com