OS X中Windows之间的转换 [英] Transition between windows in OS X
问题描述
我要制作一个带有多个视图和窗口的OS X应用程序.
I am going to make an OS X application with several views and windows.
它有几个屏幕-启动,登录/注册和主屏幕(等等).
It has several screens - splash, login/register and the main screen(and so on).
我尝试使用NSWindowControllers.但是,使用起来非常复杂,我很困惑.
I tried to use NSWindowControllers. However, it's so complex to use and I'm confused.
在视图/窗口转换中最好的体验是什么?
What is the best experience in the view/window transitions?
推荐答案
我使用的主要模式如下:
The main pattern I use is the follow:
- 创建一个
New File
User Interface
Window
并将其另存为nameYouLike
- 创建
NSWindowController
子类的New File
Cocoa
Objective-C class
,并另存为nameYouLikeDelegate
- 转到nameYouLike NSWindow并将其
File's Owner
Class
更改为nameYouLikeDelegate
- 使用
IBOutlet
将window
和其他需要的xib对象连接到nameYouLikeDelegate.h
-
在某些init/show方法中执行此操作:
- Create a
New File
User Interface
Window
and save it asnameYouLike
- Create a
New File
Cocoa
Objective-C class
ofNSWindowController
subclass and save is asnameYouLikeDelegate
- Go to nameYouLike NSWindow and change it's
File's Owner
Class
tonameYouLikeDelegate
- Connect
window
and other objects you need of xib with anIBOutlet
tonameYouLikeDelegate.h
In some init/show method do this:
- (void)showWindow {
if (!self.window) {
[NSBundle loadNibNamed:@"nameYouLike" owner:self];
}
[self.window makeKeyAndOrderFront:self];
}
以某种方式保存引用(例如,在另一个窗口的AppDelegate
或NSWindowController
中):
Save reference in some way (f.e. in AppDelegate
or NSWindowController
of another window):
nameYouLikeDelegate *fNameYouLikeDelegate;
现在,当您需要创建窗口时,可以使用:
Now when you need to create your window you use:
fNameYouLikeDelegate = [[nameYouLikeDelegate alloc] init];
并显示它:
And to show it:
[fNameYouLikeDelegate showWindow];
这篇关于OS X中Windows之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!