I am trying to fade in and out 4 different views based on the user clicking on 
a tool bar item (each toolbar item representing a different page (NSView) of 
the document.

So far from the examples I've found on line I have come up with this procedure 
and it does not work.

The function fadeInView takes two views and at the end sets the currentView to 
the one faded in. 

However, genView fades in once correctly. Non of the other views fade in, but 
do appear after the animation duration is completed. They do not fade in. Just 
pop up after 0.5 seconds. Once genView fades in once, it does not fade in 
again, and starts acting like the other windows, popping in after the animation 
duration has expired.

I've been struggling with this for some time, and from what I gather this 
should work. 

I have tried it in both blocking and nonblocking mode and it does the same 
thing. The window clears to white, and after the 0.5 seconds the view appears 
fully opaque.

What am I doing wrong?


#pragma mark -
#pragma mark Standard Call back functions


- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
....
    
    /* UI Setup */
    
    [genView setHidden:NO];
    [msds1View setHidden:YES];
    [msds2View setHidden:YES];
    [graph1View setHidden:YES];
    
    [[[wc window] contentView] addSubview:graph1View];
    [[[wc window] contentView] addSubview:msds2View];
    [[[wc window] contentView] addSubview:msds1View];
    [[[wc window] contentView] addSubview:genView];
    
 .....
    
 }



- (void) fadeInView:(NSView *) fadeInView fadeOutView:(NSView *) fadeOutView
{
    [[wc window] setContentView:fadeInView];
    
    NSDictionary *oldFadeOut = nil;
    NSDictionary *newFadeIn = nil;
    NSArray *animations;
    NSViewAnimation *animation;
    
    NSRect viewRect = [[[wc window] contentView] bounds];
        
    if (fadeInView != nil) { 
        newFadeIn = [NSDictionary dictionaryWithObjectsAndKeys:
                     fadeInView, 
                     NSViewAnimationTargetKey,
                     NSViewAnimationFadeInEffect,
                     NSViewAnimationEffectKey, 
                     [NSValue valueWithRect:viewRect],
                     NSViewAnimationEndFrameKey,
                     [NSValue valueWithRect:viewRect],
                     NSViewAnimationStartFrameKey,
                     nil];
    }
    if (fadeOutView != nil) { 
        oldFadeOut = [NSDictionary dictionaryWithObjectsAndKeys:
                      fadeOutView, 
                      NSViewAnimationTargetKey,
                      NSViewAnimationFadeOutEffect,
                      NSViewAnimationEffectKey, 
                      [NSValue valueWithRect:viewRect],
                      NSViewAnimationEndFrameKey,
                      [NSValue valueWithRect:viewRect],
                      NSViewAnimationStartFrameKey,
                      nil];
    }
    
     
    animations = [NSArray arrayWithObjects:
                  newFadeIn, oldFadeOut, nil];
    
    animation = [[NSViewAnimation alloc]
                 initWithViewAnimations: animations];
    
    
    
    // Set some additional attributes for the animation.    
    [animation setAnimationBlockingMode: NSAnimationNonblocking];
    [animation setDuration: 0.5]; // or however long you want it for
    [animation setAnimationCurve:NSAnimationEaseIn];

    [animation startAnimation]; // because it's blocking, once it returns, 
we're done

    [animation release];    

    currentView = fadeInView;
    
    

    
}


- (IBAction)swapInPrimaryView:(id)sender; 
{
    
    [[wc window] makeFirstResponder:genView];
    
    if(currentView != genView)
        [self fadeInView:genView fadeOutView:currentView];

    
}


- (IBAction)swapInMSDS1View:(id)sender; 
{
    
    
    
    [[wc window] makeFirstResponder:msds1View];
    
    
    if(currentView != msds1View)
        [self fadeInView:msds1View fadeOutView:currentView];
   

}


- (IBAction)swapInMSDS2View:(id)sender; 
{
    
    [[wc window] makeFirstResponder:msds2View];
    
    if(currentView != msds2View)
        [self fadeInView:msds2View fadeOutView:currentView];
    

}




- (IBAction)swapInGraph1View:(id)sender; 
{
    
    [[wc window] makeFirstResponder:graph1View];
    
    if(currentView != graph1View)
        [self fadeInView:graph1View fadeOutView:currentView];
    

}


                                          
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to