【问题标题】:UITableView not animating when sibling is a UIPageViewController当兄弟是 UIPageViewController 时,UITableView 没有动画
【发布时间】:2013-10-19 07:28:45
【问题描述】:

我有一个视图控制器,它有一个UITableView 和一个UIPageViewControllerUITableView's 高度首先设置为 0。单击按钮后,tableview 应该向下滑动(即高度增加)并且PageViewController 应该被按下。我是这样做的……

float yPos = 61;
CGRect fr2 = self.pageController.view.frame;// UIPageViewController
CGRect fr1 = self.categoriesTable.frame; // UITableView
if (self.categoriesTable.frame.size.height == 0.0){
    fr1.size.height = 44 * self.categories.count + 20; // categories is a datasource
    yPos = yPos + 44 * self.categories.count + 20;
}else{
    fr1.size.height = 0.0;
}
fr2.origin.y = yPos;
[UIView animateWithDuration:0.3 animations:^{
    self.pageController.view.frame = fr2;
    self.categoriesTable.frame = fr1;
}];

预期行为:tableview 和 pageviewcontroller 应该同时向下滑动。

观察到的行为:只有pageviewcontroller 向下滑动。表格视图的框架没有变化。但是,如果您再次执行此方法,则 Tableview 会向下滑动。

谁能帮我解决这个问题?如果您需要更多信息/代码,请告诉我。

【问题讨论】:

  • 不,我想同时制作动画。
  • mohkhan 你想要动画视图控制器吗?
  • 尝试重新加载表上的数据。

标签: ios objective-c uitableview uipageviewcontroller


【解决方案1】:

好吧,看来我修好了。我决定来回翻译 pageviewcontroller 以达到相同的效果。下面是工作代码。

float yPos = 0;
CGRect fr2 = self.pageController.view.frame;
CGRect fr1 = self.categoriesTable.frame;
if (self.categoriesTable.frame.size.height == 0.0){
    fr1.size.height = 44 * self.categories.count + 20;
    yPos = 44 * self.categories.count + 20;
}else{
    fr1.size.height = 0.0;
}
fr2.origin.y = yPos;

[UIView animateWithDuration:0.3 animations:^{
    self.pageController.view.layer.affineTransform = CGAffineTransformMakeTranslation(0, yPos);
    self.categoriesTable.frame = fr1;
}];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-15
    • 2021-04-15
    • 2016-06-09
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多