【问题标题】:problem in animating view in iphone sdk?iphone sdk 中动画视图的问题?
【发布时间】:2011-06-24 06:59:31
【问题描述】:

我通过显示和隐藏视图来为视图设置动画。我在 didSelectRow 中调用此方法。 当我单击单元格时,我想隐藏视图,然后我想显示视图。但我的问题是动画是从 hide 到 show 发生的,但不是从 show 到 hide。隐藏的节目突然发生,没有流畅的动画。我就是这个代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

{   

    //[tableView deselectRowAtIndexPath:indexPath animated:YES];
     Song *songObj = [songsList objectAtIndex:indexPath.row];
        [self hideMsg];
    //int delay = 20;
    //[self performSelector:@selector(hideMsg) withObject:nil afterDelay:delay];
    [self showTitleWithOptions:songObj];


}

- (void)hideMsg;

{

    CGRect frame = animatedSubView.frame;//CGRectMake(0,415,360,55)

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:75];

    frame.origin.y = 480;// here I'm changing y to 480
    animatedSubView.frame = frame;

    [UIView commitAnimations];


    frame = animatedSubView.frame;// now frame is CGRectMake(0,480,360,55)
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.75];

    frame.origin.y = 415;//now I'm changing y to 415
    animatedSubView.frame = frame;
    [UIView commitAnimations];
    theTableView.frame =CGRectMake(0,230,320,190);


}

【问题讨论】:

    标签: objective-c ios4


    【解决方案1】:

    您可以隐藏视图或在其动画时赋予 alpha 0.0,并在当前视图中进行按钮操作,当您单击它时隐藏当前视图或随 uianimation 赋予 alpha 1.0。

    【讨论】:

      【解决方案2】:

      您似乎缺少一个 .在第一个动画代码块“[UIView setAnimationDuration:75];”中的值 75 之前再次查看您的代码。

      更新

      您不能同时运行两个动画,您需要等待第一个动画完成,这是您的主要问题。尝试使用

      在 0.75 持续时间后运行第二个动画
      [self performSelector: withObject: afterDelay:];
      

      方法。

      【讨论】:

      • 嘿,对不起,我在这里粘贴代码时错过了它。我只保留了 0.75。
      猜你喜欢
      • 1970-01-01
      • 2020-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多