UIView removeFromSuperView animation delay

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-04-16T13:10:17Z Indexed on 2010/04/16 13:13 UTC
Read the original article Hit count: 689

I have a method which animates one of the subviews of UIWindow and then removes it from UIWindow using removeFromSuperview. But when I put removeFromSuperview after animation block, the animation never shows, because removeFromSuperview removes the UIView from UIWindow before the animation plays :-( How can I delay removeFromSuperview so the animation plays first, and then subview is removed? I tried [NSThread sleepForTimeInterval:1]; after animation block but that didn't have desired effect, because animation sleeps too for some reason.

My code for this method:

  - (void) animateAndRemove
    {
     NSObject *mainWindow = [[UIApplication sharedApplication] keyWindow];

     [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.8]; 
     UIView *theView = nil;
     for (UIView *currentView in [mainWindow subviews])
     {
      if (currentView.tag == 666)
      {
       currentView.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.0];
       theView = currentView;
       }
     }
     [UIView setAnimationTransition:  UIViewAnimationTransitionNone forView:theView cache:YES];
      [UIView commitAnimations]; 



 //[NSThread sleepForTimeInterval:1];

 [theView removeFromSuperview];


    }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiview