1

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?

gdubs
  • 2,724
  • 9
  • 55
  • 102

1 Answers1

1

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];
}
}
m4n1c
  • 127
  • 8
  • You can change the delay time based on your requirement. – m4n1c May 09 '13 at 08:36
  • Will that method be executed after the "commitAnimations" part? Imma try this out asap after work. – gdubs May 09 '13 at 12:20
  • also, dont I have to remove the viewtablecontainer.frame from the if else since it's already on the animationmethoddidfinish? or no? – gdubs May 09 '13 at 12:36
  • see the first code which have posted will work. Second code is to give you a more of a smoothness in animation. Ideally the first one should be helping you out. If not then you can go for second one.:) There is a minor mistake in my second code removing the viewcontainer part. I have updated it. – m4n1c May 09 '13 at 13:09
  • so using the second one, It's bombing out on the [UIView setAnimationDuration:0.5]; (first one on top) when I tap the first button then the second button then the first button again. the error is EXC_Breakpoint EXC_1386_BPT – gdubs May 10 '13 at 03:14
  • sorry i forgot to add this: [UIView setAnimationDelegate:self]; just take the latest updated code – m4n1c May 10 '13 at 05:58
  • awesome, it's now hitting the animationdidstopselector. there's another issue tho, once it hits the method it would show the uiview on the (0,0,352,700) position which shows the uiview again but without animating it. so basically you tap a button it shows up, u tap the next button and it eases out and then appears again as open without easing in. – gdubs May 13 '13 at 03:54
  • nvm it worked. I just had to add this change on to the didstopselector [UIView beginAnimations:nil context:nil]; thank you! – gdubs May 13 '13 at 03:59