0

I am trying to dismiss a UIView that I have previously added using the same animation block with a fade from alpha 0 -> alpha 100 and [self.view addSubview:newInitiateWindow.view]; The animation block executes correctly when the window is created, but when it is being dismissed, it just halts for 0.75 seconds and then disappears without ever animating. Even if I remove the removeFromSuperview and release calls it doesn't animate the fade to transparent.

Here is the code that should be generating the animation:

[UIView transitionWithView:newInitiateWindow.view
    duration:0.75
    options:UIViewAnimationOptionCurveEaseIn
    animations:^{ 
        newInitiateWindow.view.alpha = 0;
    }
    completion:^(BOOL finished){
        if(finished){
            [newInitiateWindow.view removeFromSuperview];
            [newInitiateWindow release];
            newInitiateWindow=nil;
        }
    }
];
Benjol
  • 63,995
  • 54
  • 186
  • 268
wasabi
  • 1,110
  • 10
  • 23
  • Try to add UIViewAnimationOptionAllowAnimatedContent to your options. – picknick Feb 16 '11 at 15:56
  • I tried that with the same result. It is odd since this exact same code works for the fade in (except changing the alpha = 100) and I add the subview before I start the animation block. – wasabi Feb 16 '11 at 19:02
  • Ok here is some further testing... I still can't get it to work even with the most basic block animation: [UIView animateWithDuration:1.0 animations:^{ newInitiateWindow.view.alpha = 0.0; }]; – wasabi Feb 16 '11 at 19:22
  • Is this code running on the main thread? – MHC Feb 26 '11 at 07:12

2 Answers2

1

Were you literal with the 100? It's 1.0 for full alpha, maybe that's causing some issues.

It could be an intricacy with iOS and placement of the code, but it's likely something just being mistyped, could be something indirect with a spelling error

  • You fixed it! Thanks so much. I can't believe I was such an idiot. It is interesting that it worked fading in using a value of 100, but then wouldn't fade back out using a value of 0. Switching it to 1.0f for fade in and 0.0f for fade out was the solution. – wasabi Feb 27 '11 at 05:47
0

Transitions are supposed to add/remove subviews of the view listed in the transition. They're not supposed to modify properties of the view. You want +animateWithDuration:delay:options:animation:completion: instead.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • Exactly the same behavior if I execute the following code instead :( [UIView animateWithDuration:0.75 delay:0.0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{ newInitiateWindow.view.alpha = 0; } completion:^(BOOL finished){ [newInitiateWindow.view removeFromSuperview]; [newInitiateWindow release]; newInitiateWindow = nil; }]; – wasabi Feb 16 '11 at 23:47