Question

I have a UIView that serves as the container for 2 tableviews. I have two buttons that controls how data is loaded on those tableviews. Basically when 1 button is tapped the uiview slides out to show the tableview related to that button, and when the other button gets tapped I need it to:

  1. close
  2. hide the 1st tableview
  3. then unhides the 2nd tableview
  4. then uiview slides back out

Here's what I have

[UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelay:0.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

        if(!isTableOpen){

            [self.fighterTableView setHidden:YES];
            [self.matchTableView setHidden:NO];

            isTableOpen = YES;

            viewTableContainer.frame = CGRectMake(0, 0, 352, 700);

            [self.view bringSubviewToFront:viewTableContainer];
            [UIView commitAnimations];

        }else{
            //isTableOpen = NO;
            viewTableContainer.frame = CGRectMake(-352, 0, 352, 700);
            [UIView commitAnimations];
            [self.fighterTableView setHidden:YES];
            [self.matchTableView setHidden:NO];
            viewTableContainer.frame = CGRectMake(0, 0, 352, 700);
            [UIView commitAnimations];
        }

The problem here is on the commitanimations in the else statement I'm trying to set the hidden properties then pop the uiview out again. What's happening is it just hides and unhides the tableview but the animation never happens. I feel like I need to use a delay, but Idk how, unless there's a more decent way of handling this??

Thoughts?

Was it helpful?

Solution

Instead of making use of setHidden method. Why don't you try using the setAlpha method.

It will be something like this:

[UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    if(!isTableOpen){

        [self.fighterTableView setAlpha:0.0];
        [self.matchTableView setAlpha:1.0];

        isTableOpen = YES;

        viewTableContainer.frame = CGRectMake(0, 0, 352, 700);

        [self.view bringSubviewToFront:viewTableContainer];
        [UIView commitAnimations];

    }else{
        //isTableOpen = NO;
        viewTableContainer.frame = CGRectMake(-352, 0, 352, 700);
        [UIView commitAnimations];
        [self.fighterTableView setAlpha:0.0];
        [self.matchTableView setAlpha:1.0];
        viewTableContainer.frame = CGRectMake(0, 0, 352, 700);
        [UIView commitAnimations];
    }

I would suggest you perform
[UIView setAnimationDidStopSelector:@selector(myAnimationMethod)]

Instead of setting the alpha to 1.0 of the matchTableView set it inside the myAnimationMethod.

So something like this:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(myAnimationMethodDidFinish:)]
if(!isTableOpen){

    [self.fighterTableView setAlpha:0.0];

    viewTableContainer.frame = CGRectMake(0, 0, 352, 700);

    [self.view bringSubviewToFront:viewTableContainer];
    [UIView commitAnimations];

}else{
    //isTableOpen = NO;
    viewTableContainer.frame = CGRectMake(-352, 0, 352, 700);
    [self.fighterTableView setAlpha:0.0];
    [UIView commitAnimations];
}
-(void) myAnimationMethodDidFinish:(id) sender {

[UIView setAnimationDuration:0.5];
 [UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
 if(!isTableOpen){

   [self.matchTableView setAlpha:1.0];

    isTableOpen = YES;

    viewTableContainer.frame = CGRectMake(0, 0, 352, 700);

    [self.view bringSubviewToFront:viewTableContainer];
    [UIView commitAnimations];

}else{
    //isTableOpen = NO;
    [self.matchTableView setAlpha:1.0];
    viewTableContainer.frame = CGRectMake(0, 0, 352, 700);
    [UIView commitAnimations];
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top