我在 OS X 10.10 应用程序中玩故事板。我有一个NSTableView
,当您单击特定行时会打开一个转场,该转场会转到包含NSViewController
.
你如何指定NSPoint
弹出框的箭头原点?现在,它只是指向NSTableView
中间。我以为我可以在 中做到这一点prepareForSegue
,但我似乎无法弄清楚。 prepareForSegue
似乎没有理解NSViewController
包含在NSPopover
有任何想法吗?
如果用户单击菜单图标以显示弹出框,如果用户单击弹出框以外的任何位置,弹出框将关闭,我会尝试这样做。我将行为设置为瞬态,但那不是我想的那样。
现在,如果用户单击弹出窗口上的某个位置将焦点移至该位置,则用户可以单击屏幕上的其他位置,弹出窗口将关闭。如果我可以强制将焦点放在 popover 上,我认为这也能解决我的问题。不幸的是,我也不知道该怎么做。
class AppDelegate: NSObject, NSApplicationDelegate {
let view : NSView!
let statusItem: NSStatusItem
let popover: NSPopover
let button : NSButton!
override init() {
statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-1)
if let statusButton = statusItem.button {
appStatusButton = statusButton
statusButton.image = NSImage(named: "icon128off")
statusButton.alternateImage = NSImage(named: "icon128")
statusButton.action = "onPress:"
}
popover = NSPopover()
popover.animates = false
popover.contentViewController = ViewController()
popover.behavior = .Transient
}
}
Run Code Online (Sandbox Code Playgroud)
这是视图控制器
class ViewController: NSViewController, WKNavigationDelegate{
var webView : WKWebView!
override func loadView() {
view = NSView() …
Run Code Online (Sandbox Code Playgroud) 我有一个视图控制器 (A),它将显示另一个视图控制器 (B) 作为弹出窗口。
在我的 VC (A) 中是一个带有这个 IBAction 的 NSButton:
self.presentViewController(vcPopover, asPopoverRelativeTo: myButton.bounds, of: myButton, preferredEdge: .maxX, behavior: .semitransient)
Run Code Online (Sandbox Code Playgroud)
结果:
现在我想改变我的弹出框的位置 - 我想把它向上移动。
我试过这个:
let position = NSRect(origin: CGPoint(x: 100.0, y: 120.0), size: CGSize(width: 0.0, height: 0.0))
self.presentViewController(vcPopover, asPopoverRelativeTo: position, of: myButton, preferredEdge: .maxX, behavior: .semitransient)
Run Code Online (Sandbox Code Playgroud)
但立场不变
另一个例子
我有一个分段控件。如果您单击“1”段,将显示一个弹出窗口(与上面的代码相同)。但是箭头指向段“2”而不是段“1”
我正在编写一个NSPopover
位于菜单栏右侧的 Mac 应用程序(Application is agent(UIElement)
设置为YES
)。我允许用户通过单击并向下拖动来分离弹出窗口,这会将应用程序放在窗口内。这工作正常;但是,当应用程序被拖出菜单栏并进入一个窗口时,我希望我的应用程序图标出现在 Dock 中,并在菜单栏的左侧显示特定于应用程序的菜单,就好像Application is agent(UIElement)
设置为NO
。相反,当窗口关闭并且应用程序返回到菜单栏中的弹出窗口时,我希望我的应用程序图标从 Dock 中消失并且不再在菜单栏的左侧显示特定于应用程序的菜单(Application is agent(UIElement)
已设置回到YES
)。
从这个问题,我明白Application is agent(UIElement)
在运行时改变是不可能的。然而,给出的答案是在 Objective-C 中,最后一个函数似乎从 OS X 10.9 开始贬值了。如何使我的应用程序具有与Application is agent(UIElement)
使用 Swift 在运行时更改相同的行为?
我知道显示应用windowDidBecomeMain
程序图标/菜单栏菜单会发生在windowWillClose
.
谢谢。
我有一个 OSX 应用程序,它使用 NSViewController 在我的 NSView 中交换输入输出视图。其中一种视图是 NSOutlineView。我现在想要在用户双击大纲视图中的一行时出现 NSPopover。目前我使用以下方法来显示弹出窗口:
NSRect theRect = [[NSApp keyWindow] convertRectFromScreen: NSMakeRect(700, 400, 5, 5)];
[myPopover showRelativeToRect: theRect // Window Coordinates
ofView: [[NSApp keyWindow] contentView]
preferredEdge: NSMinYEdge];
Run Code Online (Sandbox Code Playgroud)
这使得 NSPopover 出现在应用程序的底部。这有效,但我希望能够让弹出框正好出现在 NSOutlineView 的点击行下方。我交换进出的每个视图都由 NSViewController 控制,我想我可以使用 NSViewController 的 view 属性识别我的视图位置。但是,如果我替换[[NSApp keyWindow] contentView]
为myViewController.view
我收到错误,即视图没有窗口并且 NSPopover 崩溃。显然,我遇到了麻烦 1) 在 NSView 中找到相对于主窗口的点击行的坐标 2) 理解为什么我的视图没有窗口。如果有人有可以帮助我理解这些问题的建议,我将不胜感激。
2013 年 6 月 2 日更新我仍在努力解决我的问题,但我发现如果我通过 MainWindowController (myControlledView) 访问其属性,我可以获得正确的视图坐标。然后当我询问视图的原点和框架大小时,我得到了正确的值。我的 VC 将自定义视图加载为 NIB 文件,当我询问加载视图的来源时,我得到 (0,0)。我认为即使我将视图作为 NIB 加载,视图相对于窗口的位置也会保持不变?我可以将视图原点传递给我的 VC,从而正确设置 NSPopover 但这看起来相当麻烦,我认为可以通过 VC 正确访问 NIB …
我无法将我的NSPopover分离到我自己的项目中的窗口,所以为了简化我尝试了Apple示例.
我下载了Apple示例项目的新副本:http: //developer.apple.com/library/mac/samplecode/Popover/Introduction/Intro.html
它的行为相同,也就是说我无法拖动窗口来分离它.
该项目似乎提供了所有正确的窗口和控制器,并实现了detachableWindowForPopover:
委托方法.但是从不调用该方法.
有谁知道可拆卸的NSPopovers的秘密?
我想知道如何以编程方式关闭NSPopover,而不是通过触摸外部,因为我想将其分配给一个动作(例如KeyDown Enter Key或其他快捷方式)
因为我用快捷方式打开我的NSPopover,按下另一个命令关闭更合乎逻辑
要分享我的代码:
EdiciondeCuentasWC.h(NSWindowController),我称之为NSPopover
#import "EdicionDeCuentasWC.h"
#import "CambiarTipoCuentaVC.h"
@interface EdicionDeCuentasWC ()<NSPopoverDelegate>{
CambiarTipoCuentaVC *cambiarTipoCuentaVC;
}
@property (strong) IBOutlet NSPopover *popoverClasifCuentas;
@end
@implementation EdicionDeCuentasWC
-(void)mostrarPopupCambiarTipoCta{
cambiarTipoCuentaVC = (CambiarTipoCuentaVC *) _popoverCambiarTipoCuentas.contentViewController;
cambiarTipoCuentaVC.nombre_tipo_cta = arrayActivos[renglonSeleccionado][@"nombre_tipo_cta"];
cambiarTipoCuentaVC.prioridad_cta = arrayActivos[renglonSeleccionado][@"prioridad_cta"];
NSTableCellView *cellView = [_activoTableView viewAtColumn:0
row:renglonSeleccionado
makeIfNecessary:NO];
[_popoverClasifCuentas setDelegate:self];
[cambiarTipoCuentaVC inicializarDatos];
[_popoverCambiarTipoCuentas showRelativeToRect:[cellView bounds] ofView:cellView preferredEdge:NSMaxXEdge];
}
#pragma mark NSPopoverDelegate
-(void)popoverWillClose:(NSNotification *)notification{
NSPopover *popover = (NSPopover *)[notification object]; //there I have the code for managing all the returning parameters...
}
@end
Run Code Online (Sandbox Code Playgroud)
我的NSPopover的代码是在一个NSViewController(CambiarTipoCuentaVC)里面,但在那里,我没有[自我关闭]或[self performClose]使它从一个按钮或快捷方式关闭,任何帮助使它工作,我很感激...
nspopover ×7
macos ×5
swift ×3
cocoa ×2
detach ×1
lsuielement ×1
nsview ×1
objective-c ×1
window ×1
xcode5.1 ×1