【问题标题】:How to animate tableView reload on UISegmentedControl click as pushviewcontroller如何在 UISegmentedControl 点击为 pushviewcontroller 时为 tableView 重新加载设置动画
【发布时间】:2015-09-05 09:26:54
【问题描述】:

我已经在段点击时重新加载了 UITableview 数据,如下图所示:

现在我想在 UISegmentedControl 点击时为 tableView 重新加载动画,与 navigationController pushViewController 相同,但在 table view 的移动之间会出现过渡屏幕

我尝试使用以下功能,但无法完全获得我想要的 -(void)SwipeGestureRecognize{

    UISwipeGestureRecognizer * swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
    swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipeleft];

    UISwipeGestureRecognizer * swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
    swiperight.direction=UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swiperight];



}
-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
{
    //past Order

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);

    }];

    self.tableView.frame = CGRectMake(0, 0, 0-[Util window_width], [Util window_height]);

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);
    }];



    segmetControl.selectedSegmentIndex = 1;
    [self action:Nil];

}

-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
{
    //Current Order

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);

    }];

    self.tableView.frame = CGRectMake(0, 0, 0-[Util window_width], [Util window_height]);

    [UITableView animateWithDuration:0.5f animations:^{
        self.tableView.frame = CGRectOffset(self.tableView.frame,   [Util window_width],0);
     }];


    segmetControl.selectedSegmentIndex = 0;
    [self action:Nil];
}

【问题讨论】:

  • 你使用了多少个表格视图?
  • 单表视图我只是重新加载数据
  • 看到push view controller中使用的动画就像是从左向右移动。在你的情况下,它不是。您必须相应地设置框架,然后才能看到动画。

标签: ios objective-c uitableview uisegmentedcontrol uiviewanimation


【解决方案1】:

我建议您在顶部使用 UICollectionView 并使用包含 UITableView 的视图宽度制作自定义单元格 并且当段控制值更改时:滚动到您要使用的特定单元格。 也记得制作

CollectionView PagingEnabled = YES

【讨论】:

  • 我更喜欢使用表格视图而不是带有轻微动画的集合视图
  • 是的,这可以工作..在我的情况下,该段是动态的。像问答轮一样,尽管您可以使用带有水平滚动或集合视图的表格视图
  • 任何方式感谢您的建议。你能给我一些关于我目前情况的想法吗
  • 在您的情况下,您使用的是相同的 UITableView 。尝试使用 2 个不同的表视图和 Transit 。这里可能就是这种情况
【解决方案2】:

请使用以下代码。

-(void)swipeleft
{
        self.tableView.frame = CGRectMake(self.tableView.frame.size.width, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height)
        [UITableView animateWithDuration:0.5f animations:^{
            self.tableView.frame = CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);
        }];
}

 -(void)swiperight{
        self.tableView.frame = CGRectMake(-self.tableView.frame.size.width, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);

        [UITableView animateWithDuration:0.5f animations:^{
            self.tableView.frame = CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);

        }];
    }

【讨论】:

  • 我会试试你的代码并回复你的输出
  • 谢谢我已经实现了我想要的,但是在它们之间转换白色视图存在一些问题
  • 我为你的努力投了赞成票,希望你也一样
  • 你能帮帮我吗
  • 你能帮帮我吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-25
  • 2021-11-19
  • 1970-01-01
  • 2015-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多