core animation - zoom window?

Discussion in 'Mac Programming' started by Darkroom, Jun 26, 2008.

  1. Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    so i'm attempting my first core animation... decided to start small... so i have an empty window, which i would like to see animate with the window's zoom.

    1- i've enabled a layer for the content view of the myWindow in IB.
    2- i've hijacked (?) the default zoom function by adding the following void code to the myWindow.m file:

    Code:
    -(void)zoom:(id)sender
    {
    //Trigger zoom functions by writing in console.
    NSLog (@"zoom code");
    }
    
    ... and that's as far as i got so far.. hah.. i know i'm suppose to write [OBJECT animator] to employ core animation, so i guess i'm just looking for the actual zoom code... or maybe i'm totally going about this the wrong way, since i'm under the impression that core animation should be easier than this or more straight forward? any thoughts?
     
  2. thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #2
    was that a dumb question? i had just assumed that zooming code would be freely available somewhere since it's in every app, but i just couldn't find it...
     
  3. macrumors 6502

    Joined:
    Jul 25, 2006
    #3
    First of all, make sure you read the documentation for -[NSWindow zoom:] if you want implementation to behave the same way NSWindow does by default.

    Second, you're on the right track with the -animator method. -animator gives you a proxy that intercepts certain methods to perform implicit animations. In your case, within -zoom:, once you calculate the desired frame, you'll call [[self animator] setFrame:newFrame]. That will set up an implicit animation that will resize the window to the new size. (See NSAnimationContext if you want to customize this animation further.)
     
  4. macrumors 68020

    Krevnik

    Joined:
    Sep 8, 2003
    #4
    It isn't in every app, it is part of AppKit.

    When you override it, it becomes your app's responsibility to zoom it in the way your app needs. Considering you can query the size/location of the dock, it isn't too difficult to figure out the new size of the window (and save the old one).
     
  5. thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    the following code seems to work well for the animated zoom function with core animation, BUT it gives me the warnings: "myWindow may not respond to '-animator'"... any thoughts as to why i'm receiving this warning? i've selected the content view of myWindow and added allow a core animation layer, and the animation seems to be working as it should, so i'm not sure why i'm getting this warning.

    Code:
    @interface myWindow : NSWindow
    	{
    	NSRect originalFrame;
    	BOOL zoom;
    	}
    
    @implementation myWindow
    
    - (void)zoom:(id)sender
    	{
    	if (zoom)
    		{
    		[[self animator] setFrame:originalFrame display:YES];
    		zoom = NO;
    		}
    		else
    		{
    		originalFrame = [self frame];
    		[[self animator] setFrame:[[self screen] visibleFrame] display:YES];
    		zoom = YES;
    		}
    	}
    
     
  6. macrumors 6502

    Joined:
    Jul 25, 2006
    #6
    Are you sure you're compiling against the Mac OS X 10.5 SDK? NSWindow implements the NSAnimatablePropertyContainer formal protocol in 10.5+, so it should respond to -animator...
     
  7. thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #7
    oh so that's the reason... i'm targeting 10.4 SDK because i want to make the app also work with 10.4... i just assumed that core animation would be ignored for 10.4 users, much like retain/release are ignored if garbage collection is turned on for 10.5, but i guess that's not the case?

    [edit] just changed the target to 10.5 and now it compiles without any warnings... so you were absolutely right! :) so now because i want to target 10.4, i have the fun task of trying to animate the window zoom manually using NSTimer :p
     
  8. macrumors 6502

    Joined:
    Jul 25, 2006
    #8
    -[NSWindow setFrame:display:animate:] to the rescue!
     

Share This Page