PDA

View Full Version : core animation - zoom window?




Darkroom
Jun 26, 2008, 04:56 AM
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:


-(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?



Darkroom
Jun 26, 2008, 10:02 PM
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...

kpua
Jun 26, 2008, 11:10 PM
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.)

Krevnik
Jun 26, 2008, 11:17 PM
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).

Darkroom
Jun 27, 2008, 01:24 AM
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.


@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;
}
}

kpua
Jun 27, 2008, 01:35 AM
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...

Darkroom
Jun 27, 2008, 01:42 AM
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...

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

kpua
Jun 27, 2008, 02:49 AM
-[NSWindow setFrame:display:animate:] to the rescue!