简体   繁体   English

设置新创建的窗口Cocoa / Applescript的来源

[英]Set the origin of newly created window Cocoa/Applescript

I'm trying to create new window with given origin in Cocoa/AppleScript type application. 我正在尝试在Cocoa / AppleScript类型应用程序中创建具有给定来源的新窗口。

I have Main NIB with main window and another one called hud . 我有带主窗口的Main NIB和另一个名为hud窗口。 With button in main window I open new window (hud) in that way: set winn to NSWindowController's alloc()'s initWithWindowNibName_("hud") winn's showWindow_("jkb") The window is showing up. 使用主窗口中的按钮,我以这种方式打开新窗口(hud): set winn to NSWindowController's alloc()'s initWithWindowNibName_("hud") winn's showWindow_("jkb")窗口正在显示。

I want to show it in different location on the screen but without any luck. 我想在屏幕上的其他位置显示它,但是没有任何运气。 I have tried every combination of those two: 我尝试了这两个的每种组合:

set myOrigin to {x:330,y:330} or set myOrigin to {330,330} set myOrigin to {x:330,y:330}set myOrigin to {330,330}

with every line listed below: 每行列出如下:

current application's winn's class "NSWindow"'s class "NSView"'s setFrameOrigin_(mySize) --class "NSView" of class "NSWindow" of winn doesn't understand the “setFrameOrigin_” message current application's winn's class "NSWindow"'s class "NSView"'s setFrameOrigin_(mySize)不理解“ setFrameOrigin_”消息

current application's winn's NSWindow's setFrameOrigin_(myOrigin) --NSWindow of winn doesn't understand the “setFrameOrigin_” message current application's winn's NSWindow's setFrameOrigin_(myOrigin)无法理解“ setFrameOrigin_”消息

current application's winn's class "NSView"'s setFrameOrigin_(myOrigin) --class "NSView" of winn doesn't understand the “setFrameOrigin_” message current application's winn's class "NSView"'s setFrameOrigin_(myOrigin)不理解“ setFrameOrigin_”消息

current application's winn's jkb's class "NSView"'s setFrameOrigin_(myOrigin) --class "NSView" of jkb of winn doesn't understand the “setFrameOrigin_” message current application's winn's jkb's class "NSView"'s setFrameOrigin_(myOrigin)不理解“ setFrameOrigin_”消息

current application's jkb's class "NSView"'s setFrameOrigin_(myOrigin) --class "NSView" of jkb doesn't understand the “setFrameOrigin_” message current application's jkb's class "NSView"'s setFrameOrigin_(myOrigin)不理解“ setFrameOrigin_”消息

current application's jkb's NSView's setFrameOrigin_(myOrigin) --NSView of jkb doesn't understand the “setFrameOrigin_” message current application's jkb's NSView's setFrameOrigin_(myOrigin)无法理解“ setFrameOrigin_”消息

current application's jkb's class "NSView"'s setFrameOrigin_(myOrigin) --class "NSView" of jkb doesn't understand the “setFrameOrigin_” message current application's jkb's class "NSView"'s setFrameOrigin_(myOrigin)不理解“ setFrameOrigin_”消息

winn's jkb's class "NSView"'s setFrameOrigin_(myOrigin) --this class is not key value coding-compliant for the key jkb. winn's jkb's class "NSView"'s setFrameOrigin_(myOrigin)此类与密钥jkb的编码不兼容。

when I check through log ... frame I see objects so why do they not respond to setFrameOrgin_() ? 当我检查log ... frame我看到了对象,为什么它们不响应setFrameOrgin_()

Two ways to go about this: 有两种解决方法:

  1. Through IB: 通过IB:

IB

  1. Programatically: 以编程方式:

Subclass NSWindowController and set the origin in windowDidLoad: with window setFrame: 子类化NSWindowController并使用window setFrame:windowDidLoad:设置原点window setFrame:

This works in my app: 这适用于我的应用程序:

theWindow's setFrameTopLeftPoint:{60,460}

where theWindow is an instance of NSWindow (retrieved from the window controller) 其中theWindowNSWindow实例 (从窗口控制器检索)

Remember that {0,0} is the left,bottom of the main screen for this method. 请记住,{0,0}是此方法在主屏幕的底部。

Finally I solved the problem. 最后我解决了这个问题。 In hud nib I bind the window to a property hudWindow: missing value in a new, different script than main delegate. hud nib中,我将窗口绑定到property hudWindow: missing value与主委托不同的新脚本中property hudWindow: missing value In this script I have created another method awakeFromNib() . 在此脚本中,我创建了另一个方法awakeFromNib() When it is called I finally can point to the right object ( hudWindow ) and set its parameters. 当它被调用时,我最终可以指向正确的对象( hudWindow )并设置其参数。 Thank you 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM