Re: Temporarily enabling layer backing for NSView
Re: Temporarily enabling layer backing for NSView
- Subject: Re: Temporarily enabling layer backing for NSView
- From: Indragie Karunaratne <email@hidden>
- Date: Fri, 17 Jun 2011 22:33:05 -0600
Super late reply here, but I just tried that and it still doesn't work. It seems to work every now and then randomly but other times it doesn't work at all. Sounds like some sort of timing issue.
On 2011-05-18, at 1:04 AM, Josh Abernathy wrote:
> Try doing the animation one runloop after calling -setWantsLayer:, kinda like this (typed in Mail):
>
> - (void)doAnimation {
> [parentView setWantsLayer:YES];
> [self performSelector:@selector(noSeriouslyDoTheAnimation) withObject:nil afterDelay:0];
> }
>
> - (void) noSeriouslyDoTheAnimation {
> CATransition *transition = [CATransition animation];
> transition.type = kCATransitionPush;
> transition.subtype = kCATransitionFromLeft;
> transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
> [CATransaction begin];
> [CATransaction setCompletionBlock:^(void) {
> [parentView setWantsLayer:NO];
> }];
> [parentView setAnimations:[NSDictionary dictionaryWithObject:transition forKey:@"subviews"]];
> [[parentView animator] replaceSubview:firstView with:secondView];
> [CATransaction commit];
> }
>
>
> On May 17, 2011, at 7:59 PM, Indragie Karunaratne wrote:
>
>> Hi all,
>>
>> I'm trying to use CATransition in my app to provide an animated slide transition when swapping views. I don't want to permanently layer back my views because they cause various glitches (no subpixel antialiasing, resize issues when backed with a CATiledLayer, etc.) To get around this, I want to temporarily layer back my view, run the animation, and then disable layer backing after the animation completes. This is my code thus far:
>>
>> CATransition *transition = [CATransition animation];
>> transition.type = kCATransitionPush;
>> transition.subtype = kCATransitionFromLeft;
>> transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
>> [parentView setWantsLayer:YES];
>> [CATransaction begin];
>> [CATransaction setCompletionBlock:^(void) {
>> [parentView setWantsLayer:NO];
>> }];
>> [parentView setAnimations:[NSDictionary dictionaryWithObject:transition forKey:@"subviews"]];
>> [[parentView animator] replaceSubview:firstView with:secondView];
>> [CATransaction commit];
>>
>> With this code, the animation doesn't run (the views just get swapped without animation but the completion block is still called). The problem seems to be the fact that I'm calling -setWantsLayer: immediately before the animation begins. If I call this method in -awakeForNib, the animation will run. I'm thinking that this might be some sort of runloop issue, but I have no idea what I can do to work around this. I've tried moving my -setWantsLayer: call to various places within the animation method but this has no effect.
>>
>> Any help is greatly appreciated.
>> Thanks,
>> Indragie
>> --------
>> http://indragie.com _______________________________________________
>>
>> 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
>
_______________________________________________
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