Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView animates slide in but not slide out using block animation method

I have a UIView called geopointView. I want to animate slide in this UIview on main view frame when a button (myButton) is pressed. If myButton is pressed again UIview should slide out of frame. myButton calls following method "optionsCalled"

-(void) optionsCalled
{
if (![[self.view subviews] containsObject:geopointView] &&checkForGeopointViewAnimation ==0) {

        [self.view addSubview:geopointView];
        geopointView.frame = CGRectMake(0,430,320,30);
        [UIView animateWithDuration:0.3f 
                         animations:^{
                             geopointView.frame = CGRectMake(0, 350, 100, 80);
                         }
                         completion:^(BOOL finished){
                             checkForGeopointViewAnimation = 1 ;
                         }];

    }
    if ([[self.view subviews] containsObject:geopointView] && checkForGeopointViewAnimation ==1)
    {

        geopointView.frame = CGRectMake(0, 350, 100, 80);
        [UIView animateWithDuration:0.3f 
                         animations:^{
                             geopointView.frame = CGRectMake(0,430,320,30);
                         }
                         completion:^(BOOL finished){
                             checkForGeopointViewAnimation = 0 ;
                         }];

        [geopointView removeFromSuperview];

    }

}

here checkForGeopointViewAnimation is a global variable defined to ensure slide in and out are not called at one time.

Problem with this code is that UIview slides in animatedly but it does not animate slide out action. it just disappears from main frame. Do I need to use any time here so that there is delay in calling add and remove UIview functions?

Thanks for any help in advance

like image 523
alekhine Avatar asked Sep 14 '11 11:09

alekhine


2 Answers

Try [geopointView removeFromSuperview]; after the completion of the animation

like image 126
visakh7 Avatar answered Sep 25 '22 19:09

visakh7


Maybe you need to call [geopointView removeFromSuperview]; in your completion block instead?

like image 37
phi Avatar answered Sep 22 '22 19:09

phi