Re: Layer Backed Views and CoreAnimation neither animate nor stay in place
Re: Layer Backed Views and CoreAnimation neither animate nor stay in place
- Subject: Re: Layer Backed Views and CoreAnimation neither animate nor stay in place
- From: Brian Christensen <email@hidden>
- Date: Fri, 27 Jun 2008 13:16:02 -0400
On Jun 27, 2008, at 08:56, Chilton Webb wrote:
(3) Even when everything else is working right, the first time I
perform my animation method, the animation does not work. Instead,
it quickly swaps out the old view with the new one, and displays it
in the foreground, on top of all other views, even if all other
views are layer backed. This is obviously *not* 'replacing' the view
in the order I want. After that, it animates properly, but on top of
the other views instead of behind them.
I'm surprised it doesn't work as intended. Maybe it's a bug in the
replaceSubview:with: method. If you change your testSwap: method to
the following it should maintain the view ordering:
- (IBAction) testSwap:(id) sender
{
// (2) If I set this anywhere else, the animations don't work.
// [self setWantsLayer:YES];
// (3) See notes above
ColoredSubView *svx = [[ColoredSubView alloc]
initWithFrame:NSMakeRect(50,50,200,200)];
[svx setColor:[self anothercolor]];
// [[self animator] replaceSubview:[[self subviews] objectAtIndex:1]
with: svx];
NSView *viewToReplace = [[self subviews] objectAtIndex:1];
[[self animator] addSubview:svx positioned:NSWindowAbove
relativeTo:viewToReplace];
[[viewToReplace animator] removeFromSuperview];
[svx release];
}
It looks like you'll have to add this as well:
- (void)awakeFromNib
{
[self setWantsLayer:YES];
}
Your transition probably won't work as intended with this solution
though (it works fine with the default fade animation, however), so to
get the effect you want you may need to position the new view outside
the visible boundaries of the superview and then use something like
this to perform the transition:
[NSAnimationContext beginGrouping];
[NSAnimationContext setDuration:0.5];
[[svx animator] setFrameOrigin:destinationFrameOrigin];
[[viewToReplace animator]
setFrameOrigin:somewhereOutsideVisibleBoundaries];
[NSAnimationContext endGrouping];
[viewToReplace performSelector:@selector(removeFromSuperview)
withObject:nil afterDelay:0.5];
(I'm not sure that the transition you specified would work with
replaceSubview:with: either. It seems to perform the animation on the
entire superview, not just the subview being changed.)
/brian
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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