Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
433 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...