Re: Resizing NSView with CABasicAnimation

2008-04-15 Thread Bill Dudney

Hi Michael,

Are you layer backed or layer hosting (i.e. did you se the layer  
explicitly?) If you are layer hosting then add he explicit animation  
to the view instead of the layer (when layer backing you should not  
manipulate the layer directly).


If you are doing layer hosting then try leaving the 'from' and 'to'  
values out.


HTH,


-bd-
http://bill.dudney.net/roller/objc

On Apr 15, 2008, at 6:54 PM, Michael Fey wrote:


Folks,

I'm trying to perform a basic resize on an NSView subclass using an  
explicit animation.  The code compiles and runs without crashing,  
but also without performing the resize.  I'm obviously missing  
something very basic, but I haven't been able to find the answer  
elsewhere.  Here's my sample code:


	CABasicAnimation* resizeAnimation = [CABasicAnimation  
animationWithKeyPath:@"frame.size"];

[resizeAnimation setDelegate:self];
resizeAnimation.duration = 3.0;
resizeAnimation.fromValue = [NSValue valueWithRect:[self frame]];
resizeAnimation.toValue = [NSValue valueWithRect:largerRect];
[[self layer] addAnimation:resizeAnimation forKey:@"frame"];

Thanks for any insights.

Regards,
Michael Fey
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/bdudney%40mac.com

This email sent to [EMAIL PROTECTED]


___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Resizing NSView with CABasicAnimation

2008-04-15 Thread Scott Anguish

why use explicit at all?

just work through the animator object and set the new value... if  
necessary you can surround it with a transaction ot change the size.


assuming 'self' is the View


[[self animator] setFrame:largerRect];


done.

it'll work with or without layer backing being turned on.

in the below sample at least one problem (aside form it being entirely  
unnecessary and that you shouldn't manipulate the layer on a layer- 
backed view) is that you are trying to do a progression of rectangles  
into a CGSize.


On Apr 15, 2008, at 8:54 PM, Michael Fey wrote:

Folks,

I'm trying to perform a basic resize on an NSView subclass using an  
explicit animation.  The code compiles and runs without crashing,  
but also without performing the resize.  I'm obviously missing  
something very basic, but I haven't been able to find the answer  
elsewhere.  Here's my sample code:


	CABasicAnimation* resizeAnimation = [CABasicAnimation  
animationWithKeyPath:@"frame.size"];

[resizeAnimation setDelegate:self];
resizeAnimation.duration = 3.0;
resizeAnimation.fromValue = [NSValue valueWithRect:[self frame]];
resizeAnimation.toValue = [NSValue valueWithRect:largerRect];
[[self layer] addAnimation:resizeAnimation forKey:@"frame"];

Thanks for any insights.


___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Resizing NSView with CABasicAnimation

2008-04-15 Thread Scott Anguish


On Apr 15, 2008, at 11:01 PM, Bill Dudney wrote:

Hi Michael,

Are you layer backed or layer hosting (i.e. did you se the layer  
explicitly?) If you are layer hosting then add he explicit animation  
to the view instead of the layer (when layer backing you should not  
manipulate the layer directly).




I don't think it matters.  If he's trying to resize the view, the  
layers aren't relevant.  this can be done trivially through the view's  
animator with or without layer backing/layer hosting/ being on.



If you are doing layer hosting then try leaving the 'from' and 'to'  
values out.



___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Resizing NSView with CABasicAnimation

2008-04-16 Thread Michael Fey

Bill,

Given that you've "written the book" on Core Animation, I really  
appreciate your insights.  Since my view is layer backed (I called  
setWantsLayer:YES on a parent view), then my call to [[self layer]  
addAnimation...] should be [self addAnimation] instead?  The other  
thing that I'm not sure about is the NSString values that I'm passing  
in for animationWithKeyPath: and addAnimation:forKey:.  Do those look  
correct for resizing the view?


Scott,

Your suggesstion to do away with the explicit animation is a good one,  
so let me explain my reasons for using it:  I am trying to chain  
together a series of animations and I don't want one to happen before  
the previous one has finished.  By using a CABasicAnimation I can  
specify a delegate (in this case my NSView subclass) that has the  
animationDidStart and animationDidEnd methods.  Using these delegate  
methods I intended to control the series of animations.  If there is a  
better way of waiting for one animation to finish before starting  
another one I am all ears, especially if I can do it with implicit  
animations.



Thanks to both of you,
 Michael


On Apr 16, 2008, at 1:02 AM, Scott Anguish wrote:



On Apr 15, 2008, at 11:01 PM, Bill Dudney wrote:

Hi Michael,

Are you layer backed or layer hosting (i.e. did you se the layer  
explicitly?) If you are layer hosting then add he explicit  
animation to the view instead of the layer (when layer backing you  
should not manipulate the layer directly).




I don't think it matters.  If he's trying to resize the view, the  
layers aren't relevant.  this can be done trivially through the  
view's animator with or without layer backing/layer hosting/ being on.



If you are doing layer hosting then try leaving the 'from' and 'to'  
values out.




___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: Resizing NSView with CABasicAnimation

2008-04-16 Thread Bill Dudney

Hi Michael,

My pleasure. Although Scott wrote the docs that I used to learn CA so  
I could write a book ;)


As Scott pointed out if you are simply resizing the view you don't  
necessarily need layers to accomplish animation as the view's animator  
will do the animation just fine. If you are doing other stuff that  
requires a layer then ignore this comment.


So to get chained animations I would suggest an animation group (added  
to the view, not the layer) something like this (stream of  
consciousness code here so YMMV);


ani1 = [CABasicAnimation animationWithKeyPath:@"frameSize"];
ani1.duration = 1.0f;
ani2 = [CABasicAnimation animatoinWithKeyPath:@"alphaValue"];
ani2.beginTime = 1.0f;
ani2.duration = 1.0f;
ani2.toValue = 0.5f;

myGroup.animations = [NSArray arrayWithObjects:ani1, ani2, nil];
myGroup.duration = 2.0f;
myView.animations = [NSDict dictWithObj:myGroup forKey:@"frameSize"];

now when you tweak the frameSize of myView like thus;

myView.frameSize = newSize;

your group animation will fire. The frameSize animation will run for 1  
second fromt he old size to the new size and the alphaValue animation  
will run starting at 1 second and willr un for one second.


Only reason that a layer is required for this is the opacity, if you  
are animating something that does not require a layer then you could  
do the same thing without layers in the picture at all.


HTH,


-bd-
http://bill.dudney.net/roller/objc

On Apr 16, 2008, at 7:43 AM, Michael Fey wrote:


Bill,

Given that you've "written the book" on Core Animation, I really  
appreciate your insights.  Since my view is layer backed (I called  
setWantsLayer:YES on a parent view), then my call to [[self layer]  
addAnimation...] should be [self addAnimation] instead?  The other  
thing that I'm not sure about is the NSString values that I'm  
passing in for animationWithKeyPath: and addAnimation:forKey:.  Do  
those look correct for resizing the view?


Scott,

Your suggesstion to do away with the explicit animation is a good  
one, so let me explain my reasons for using it:  I am trying to  
chain together a series of animations and I don't want one to happen  
before the previous one has finished.  By using a CABasicAnimation I  
can specify a delegate (in this case my NSView subclass) that has  
the animationDidStart and animationDidEnd methods.  Using these  
delegate methods I intended to control the series of animations.  If  
there is a better way of waiting for one animation to finish before  
starting another one I am all ears, especially if I can do it with  
implicit animations.



Thanks to both of you,
Michael


On Apr 16, 2008, at 1:02 AM, Scott Anguish wrote:



On Apr 15, 2008, at 11:01 PM, Bill Dudney wrote:

Hi Michael,

Are you layer backed or layer hosting (i.e. did you se the layer  
explicitly?) If you are layer hosting then add he explicit  
animation to the view instead of the layer (when layer backing you  
should not manipulate the layer directly).




I don't think it matters.  If he's trying to resize the view, the  
layers aren't relevant.  this can be done trivially through the  
view's animator with or without layer backing/layer hosting/ being  
on.



If you are doing layer hosting then try leaving the 'from' and  
'to' values out.




___

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:
http://lists.apple.com/mailman/options/cocoa-dev/bdudney%40mac.com

This email sent to [EMAIL PROTECTED]


___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]