首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSPopover未出现

NSPopover未出现
EN

Stack Overflow用户
提问于 2012-07-16 03:49:01
回答 2查看 1.7K关注 0票数 2

我真的希望我能更具体,但不幸的是,我不能。所有合适的对象都是非空的,并且所有合适的方法调用(可能)都是成功的,但是我的NSPopover从来没有出现过。委托方法也不会被调用。

代码语言:javascript
复制
// 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];
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-16 06:48:47

事实证明坐标系是错误的:

代码语言:javascript
复制
NSRect theRect = [[NSApp keyWindow] convertRectFromScreen: NSMakeRect(700, 400, 5, 5)];
[tagPopover showRelativeToRect: theRect // Window Coordinates
                        ofView: [[NSApp keyWindow] contentView]
                 preferredEdge: NSMinYEdge];

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

票数 3
EN

Stack Overflow用户

发布于 2012-07-16 03:56:21

我怀疑tagPopoverViewController.view.frame是NSZeroRect,因为frames是在它们开始出现在屏幕之前设置的(例如,它们从xibs/故事板出来是没有意义的)。你确定你需要那条线吗?文档提到,contentSize无论如何都要绑定到内容视图的大小。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11495082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档