I'm trying to apply a fade to an UIView I created programmatically on the top of another.
[UIView animateWithDuration:0.5 animations:^(void) {
[self.view setAlpha:0];
}
completion:^(BOOL finished){
[self.view removeFromSuperview];
}];
The finished event is called properly after exactly 0.5 seconds, but I don't see any fade (I should see the UIView on the bottom).
If instead of using the alpha, I move away the UIView it works (I see the bottom UIView while the top UIView slides away), so it seems to be a problem related to alpha, but I can't figure out what's wrong!
[UIView animateWithDuration:0.5 animations:^(void) {
CGRect o = self.view.frame;
o.origin.x = 320;
self.view.frame = o;
}
completion:^(BOOL finished){
[self.view removeFromSuperview];
}];
I used alpha animations previously and they works in this way usually...
No, it is not needed in this case. animations and completion are not retained by self so there is no risk of strong retain cycle.
The contents of your block are performed on the main thread regardless of where you call [UIView animateWithDuration:animations:] .
Try setting opaque
to NO
explicitly. I had the same problem and setting that solved my problem. Apparently, opaque views just don't seem to play well with alpha.
Credit goes to Hampus Nilsson's comment though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With