【问题标题】:Show and hide UITableView with animation用动画显示和隐藏 UITableView
【发布时间】:2014-11-04 11:03:57
【问题描述】:

我正在尝试显示和隐藏带有动画“从左到右和从右到左的过渡”的 tableView

这我已经厌倦了,但在 CGRectMake 中使用了随机值之后,

谁能帮我解决一下

    -(void)Display:(UITableView *)tableView :(UIView *)view{
         tableView.alpha=1;
        [UIView animateWithDuration:0.35
                         animations:^{
                                 tableView.frame = CGRectMake(-209, 440, 180, 209);

                         }
                         completion:^(BOOL finished){

                             [tableView setHidden:YES];

                         }
         ];
    }

-(void)Hide:(UITableView *)tableView :(UIView *)view :(int )tb{
    tableView.alpha=1;
    [tableView setHidden:NO];

    [UIView animateWithDuration:.45
                     animations:^{
                          tableView.frame = CGRectMake(3, 442, 180, 209);

                     }
     ];
}

【问题讨论】:

  • 请告诉我们你已经尝试过什么。
  • @Dave 我已经累了
  • @fourthnovember 你说它在上面的帖子中有效。你有什么问题?

标签: ios objective-c xcode uitableview animation


【解决方案1】:

您可以使用此代码:

[UIView transitionFromView:firstView
                    toView:secondView//table view
                  duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                completion:^(BOOL finished) {

                    [firstView.superView addSubview:secondView];

                    [firstView.superView sendSubviewToBack:firstView];
                }];

【讨论】:

  • mityaika07 谢谢,我尝试了你的解决方案,它有效,但对于所有视图,不仅仅是我的带有翻转而不是左右滑动过渡的桌面视图,我已经尝试过这两种方法,但我得到了CGRectMake 迷路了,也许有更好的方法来设置从左到右的过渡?不以随机方式设置 CGRectMake
【解决方案2】:

很难从您的问题中看出“从左到右和从右到左的过渡” 你想要这样的东西吗...?

用于向左移动

    [UIView animateWithDuration:1.0f
                          delay:0.0f
                        options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
                     animations:^{


                         self.tableView.frame = CGRectMake(0.0f, -self.tableView.frame.size.width, self.tableView.frame.size.width, self.tableView.frame.size.height);

                     }
                     completion:NULL];

用于制作正确的动画

    [UIView animateWithDuration:1.0f
                          delay:0.0f
                        options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
                     animations:^{


                         self.tableView.frame = CGRectMake(0.0f, self.view.bounds.size.width, self.tableView.frame.size.width, self.tableView.frame.size.height);

                     }
                     completion:NULL];

用于动画

    [UIView animateWithDuration:1.0f
                          delay:0.0f
                        options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
                     animations:^{


                         self.tableView.frame = CGRectMake(0.0f, 0.0f, self.tableView.frame.size.width, self.tableView.frame.size.height);

                     }
                     completion:NULL];

您可以将表格重新加载等放入您的完成块中吗?然后将 tableView 动画化?

【讨论】:

  • 你能解释一下 CGRectMake 中的第一个点值吗,它们在你的样本中工作得很好,但我只需将结束点设置在左上角视图的末尾。做效果幻灯片和隐藏
  • 当然,所以 CGRectMake 的顺序是 origin.X, origin.Y, width, height... 所以向右移动视图(在本例中为 tableview).. 我们增加 origin.x如果我们想把它向左移动,我们就减少。
【解决方案3】:

如果您想要像 Facebook 这样的动画,请使用:- ECSlidingViewController

http://kingscocoa.com/tutorials/slide-out-navigation/

或者

如果您想要正常动画,请设置帧并将 alpha 从 1.0 减少到 0.0 持续时间。

【讨论】:

  • 谢谢,但这不是我想做的,我只是想用动画显示和隐藏 uitableView
  • 好的,然后使用它可能有用:- 最初设置 tableview 的框架 (0,0,0,460) 然后在动画部分 (0,0,320,460) - (void)animateView:(UIView *)theView toPosition:(CGPoint) thePosition { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:2]; // 将中心设置为最终位置 // 将变换设置回身份,从而撤消之前的缩放效果。 theView.frame = CGRectMake(0,0,320,460); theView.transform = CGAffineTransformIdentity; [UIView 提交动画]; }
猜你喜欢
  • 2018-10-20
  • 2010-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 2012-02-25
  • 2016-02-02
相关资源
最近更新 更多