Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
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 ?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.