Transition between windows in OS X [closed]

2019-05-22 23:56发布

问题:

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 File User Interface Window and save it as nameYouLike
  • Create a New File Cocoa Objective-C class of NSWindowController subclass and save is as nameYouLikeDelegate
  • Go to nameYouLike NSWindow and change it's File's Owner Class to nameYouLikeDelegate
  • Connect window and other objects you need of xib with an IBOutlet to nameYouLikeDelegate.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 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];
    


回答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];