1

我有一个 UIView 作为 2 个表视图的容器。我有两个按钮来控制如何在这些 tableviews 上加载数据。基本上,当点击 1 个按钮时,uiview 会滑出以显示与该按钮相关的 tableview,而当另一个按钮被点击时,我需要它:

  1. 隐藏第一个表视图
  2. 然后取消隐藏第二个表格视图
  3. 然后 uiview 滑出

这就是我所拥有的

[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];
        }

这里的问题出在 else 语句中的提交动画上,我试图设置隐藏属性,然后再次弹出 uiview。发生的事情是它只是隐藏和取消隐藏 tableview 但动画永远不会发生。我觉得我需要使用延迟,但我知道如何,除非有更体面的方式来处理这个?

想法?

4

1 回答 1

1

而不是利用setHidden方法。你为什么不尝试使用该setAlpha方法。

它会是这样的:

[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];
    }

我建议你表演
[UIView setAnimationDidStopSelector:@selector(myAnimationMethod)]

而不是将 matchTableView 的 alpha 设置为 1.0,而是将其设置在myAnimationMethod.

所以是这样的:

[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];
}
}
于 2013-05-09T07:28:44.030 回答