Re: The simplest way to fade out a view
Re: The simplest way to fade out a view
- Subject: Re: The simplest way to fade out a view
- From: Gustavo Pizano <email@hidden>
- Date: Fri, 20 May 2011 23:50:41 +0200
Nick try to put the fillMode property of the animation also
something like
alphaAnimation.fillMode = kCAFillModeForwards;
and removeOnCompletion to NO;
no matter what key you put when adding the animation to the layer, the imprtant is the key you use when creating the animation, so "opacity" should be on the CAAnimatiion method call, and the opacityAnimation or alpahaAnimation or wherever you wanna call it when you add the animation to the layer, this is the key that identifies the animation ... i think .. :S.. hehe too mcuh wine. :P
On May 20, 2011, at 10:21 PM, Nick wrote:
> Chase,
> thank you for your responses.
>
> I actually tested both your code and the code of Gustavo. For me the result was the same - the opacity changes back to 1.0 when the animation had finished and then i hide it, which still causes blinking...
> Before the animation starts, i need to set the opacity to 1.0 for your code - the "animator" uses it as starting value (and the final value is specified by the line alphaAnimation.toValue = [NSNumber numberWithFloat:0.0];).
>
> So, since in the Layer Tree the opacity is 1.0, after the animation finishes, the view becomes opaque again.
>
> The only thing that worked for me was [[[myView] animator] setAlphaValue:0.0], which did not end up with the opacity 1.0 after animation had finished, but i need to use a timer to hide the view. I only was thinking there would be a "simpler" solution.
>
> Well, i guess i made up a big problem from a little desire to make my application to look more "alive" to the user :-)
>
> Here is a full code that ends up with the opacity 1.0 (instead of 0.0 as i needed to have)
>
> CABasicAnimation * alphaAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
> alphaAnimation.delegate = self;
> alphaAnimation.removedOnCompletion = YES;
> alphaAnimation.autoreverses = NO;
> alphaAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
> alphaAnimation.duration = 1.0f;
> alphaAnimation.toValue = [NSNumber numberWithFloat:0.0];
>
>
> [[theView layer] setOpacity:1.0];
> [[theView layer] addAnimation:alphaAnimation forKey:@"opacity"];
>
>
>
>
> 2011/5/20 Chase Latta <email@hidden>
> Did you try making that change in your code? If yes, is your view layer backed?
>
> I work mainly on iOS so I could be missing something but the code worked without blinking for me on 10.6.
>
> What is happening, as I think I understand it, is that by setting the opacity of your view's layer to 0.0 you trigger the implicit animation for opacity. But if you add an animation for the opacity key path that animation will be used. What you are doing is simply adding an animation. When it finishes it jumps back to the original value before you hide it. You need to set the opacity of your layer to zero at some point in your code. The animation that you see is actually the animation of the presentationLayer.
>
> I could be wrong on how all this works but my quick test does not cause the view to blink.
>
> Chase
>
>
> On May 20, 2011, at 12:26 PM, Nick <email@hidden> wrote:
>
>> Chase,
>> the animation itself worked and works - either with your code or with Gustavo's.
>>
>> But after the animation finishes, the opaqueness of the view again becomes 1.0 again. Then the "animationDidStop" gets called and the view disappears. But before disappearing, it annoyingly blinks (so, the opaqueness changes like this: 1.0, 0.9, 0.8, ..., 0.1, 1.0, hidden).
>>
>> I am wondering how could i make it save the final state of the animation - to remain transparent when the "animationDidStop" callback gets called - which will allow the view not to blink.
>>
>> I understand (i hope i do :-) ) that i am actually changing the opaqueness of the layer (i.e., of the temporary graphical representation) and not of the view itself, but maybe i could get rid of blinking somehow.
>> Thank you!
>>
>> 2011/5/20 Chase Latta <email@hidden>:
>> >> How could i force the animation to actually change the alpha value
>> >> from 1.0 to 0.0 and make it stay 0.0 unless i change it back?
>> >
>> > Change your code to look like this:
>> >
>> > CABasicAnimation * alphaAnimation = ...
>> > ...
>> > [[theView layer] setOpacity:0.0]; // Set your opacity here
>> > [[theView layer] addAnimation:alphaAnimation forKey:@"opacity"];
>> > // Note the key
>> > }
>> >
>> > By setting the key to @"opacity" instead of @"opacityAnimation" your
>> > animation will used instead of the default animation when you call
>> > [CALayer setOpacity:].
>> >
>> > There is a good WWDC talk about animation on the ipad that addresses
>> > this. I don't remember the exact talk, though.
>> >
>> > Chase
>> >
>>
>
_______________________________________________
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