Re: View swap using "push" animation
Re: View swap using "push" animation
- Subject: Re: View swap using "push" animation
- From: Martin Hewitson <email@hidden>
- Date: Wed, 11 Nov 2009 07:45:25 +0100
I ended up doing exactly this in the last couple of days but I used
NSAnimation. I don't see any performance problems.
I have two views which are subviews of a main view. The main view is
sized so that only one subview is visible (which means you have to
take care of the subview sizes if the main view resizes). Each view
has a button which fires the action below:
In the code I've set:
kFrameAnimationLength=0.3;
kFrameOffsetFactor=1.05;
- (IBAction)swapView:(id)sender
{
NSRect frame1 = [view1 frame];
NSRect frame2 = [view2 frame];
if (frame1.origin.x >= 0) {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext]
setDuration:kFrameAnimationLength];
NSRect newFrame = NSMakeRect(-kFrameOffsetFactor*frame1.size.width,
frame1.origin.y,
frame1.size.width,
frame1.size.height);
[[view1 animator] setFrame:newFrame];
[[view2 animator] setFrame:frame1];
[NSAnimationContext endGrouping];
} else {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext]
setDuration:kFrameAnimationLength];
NSRect newFrame = NSMakeRect(kFrameOffsetFactor*frame2.size.width,
frame2.origin.y,
frame2.size.width,
frame2.size.height);
[[view2 animator] setFrame:newFrame];
[[view1 animator] setFrame:frame2];
[NSAnimationContext endGrouping];
}
}
To handle resizing the views, I listen for window resizes in the app
delegate:
// The sliding views need to be resized when the window resizes.
[nc addObserver:self
selector:@selector(handleWindowResize:)
name:NSWindowDidResizeNotification
object:[self window]];
// If the window resizes then our sliding views need to reposition
themselves.
- (void)handleWindowResize:(NSNotification*)aNote
{
NSRect frame1 = [view1 frame];
NSRect frame2 = [view2 frame];
if (frame1.origin.x < 0) {
NSRect newFrame = NSMakeRect(-kFrameOffsetFactor*frame2.size.width,
frame2.origin.y,
frame2.size.width,
frame2.size.height);
[view1 setFrame:newFrame];
} else {
NSRect newFrame = NSMakeRect(kFrameOffsetFactor*frame2.size.width,
frame2.origin.y,
frame2.size.width,
frame2.size.height);
[view2 setFrame:newFrame];
}
}
Martin
On Nov 11, 2009, at 3:18 AM, Matt Neuburg wrote:
On Mon, 9 Nov 2009 22:18:25 -0700, PCWiz <email@hidden>
said:
I want to swap out one view with another by pushing the old view
aside
to slide in a new view (the kCATransitionPush type). To use
CoreAnimation I need to work with CALayers for my views. The problem
is that attaching a backing layer to my window content view through
setWantsLayer distorts everything in the view.
I'm not sure if this has something to do with the fact that I'm using
a subclass of NSWindow called MAAttachedWindow (http://mattgemmell.com/source
), which is a HUD style transparent popup window of sorts that
attaches to another object.
I can provide screenshots of this distortion if needed.
Yes, please do.
Layers don't play well with every kind of built-in control. My
solution (in
my JACTVocab application, which you can download) is to take a
screenshot of
the "before" and "after" appearance of the window - so now I've got
two
images - and temporarily interpose a second window in which I
perform the
push transition from one image to the other. You might have to
resort to
something like that. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Martin Hewitson
Albert-Einstein-Institut
Max-Planck-Institut fuer
Gravitationsphysik und Universitaet Hannover
Callinstr. 38, 30167 Hannover, Germany
Tel: +49-511-762-17121, Fax: +49-511-762-5861
E-Mail: email@hidden
WWW: http://www.aei.mpg.de/~hewitson
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden