问题
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).
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?
回答1:
The main pattern I use is the follow:
- Create a
New FileUser InterfaceWindowand save it asnameYouLike - Create a
New FileCocoaObjective-C classofNSWindowControllersubclass and save is asnameYouLikeDelegate - Go to nameYouLike NSWindow and change it's
File's OwnerClasstonameYouLikeDelegate - Connect
windowand other objects you need of xib with anIBOutlettonameYouLikeDelegate.h In some init/show method do this:
- (void)showWindow { if (!self.window) { [NSBundle loadNibNamed:@"nameYouLike" owner:self]; } [self.window makeKeyAndOrderFront:self]; }Save reference in some way (f.e. in
AppDelegateorNSWindowControllerof another window):nameYouLikeDelegate *fNameYouLikeDelegate;Now when you need to create your window you use:
fNameYouLikeDelegate = [[nameYouLikeDelegate alloc] init];And to show it:
[fNameYouLikeDelegate showWindow];
回答2:
How would you like to transition? It's probably unnecessary to transition between windows in your case. Better you make a NSViewController and transition between the subviews of the window. You should check out the basics of Cocoa.
You can then use the animator property of the views.
[[self.view animator] setAlphaValue:0.0];
来源:https://stackoverflow.com/questions/12889534/transition-between-windows-in-os-x