UIButton animation acts weird.

Discussion in 'iOS Programming' started by erdinc27, Aug 1, 2014.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    i want to make a slide animation when a button tapped. But it acts really weird. here my codes are.
    Code:
    - (IBAction)showHideView:(UIButton *)sender
    {
        if (self.isViewVisible)
        {
            [UIView animateWithDuration:0.5 animations:^{
                
                self.btnKulak.frame = CGRectMake(296, 205, 24, 62);
                [self.btnKulak setBackgroundImage:[UIImage imageNamed:@"kapaliKulak.png"] forState:UIControlStateNormal];
    
            } completion:^(BOOL finished) {
                self.isViewVisible = NO;
            }];
        }
        else
        {
            [UIView animateWithDuration:7.5 animations:^{
                
                self.btnKulak.frame = CGRectMake(0, 205, 24, 62);
                [self.btnKulak setBackgroundImage:[UIImage imageNamed:@"acikKulak.png"] forState:UIControlStateNormal];
               
            } completion:^(BOOL finished) {
                self.isViewVisible = YES;
            }];
        }
        
    }
    
    the if blocks work normal but in the else block the UIButton doesnt stop. First it goes to 0 point and then starts to slide right side. I mean its x position increase. But i want it to stop in the point 0. So how can i achieve it ? what is the wrong in these code ?
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    I don't see anything wrong with the code you posted. My guess is that the method is getting called again from somewhere else in your code. I'd put a break point on the first IF statement and investigate that possibility.
     

Share This Page