当兄弟是 UIPageViewController 时,UITableView 没有动画

Posted

技术标签:

【中文标题】当兄弟是 UIPageViewController 时,UITableView 没有动画【英文标题】:UITableView not animating when sibling is a UIPageViewController 【发布时间】: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 你想要动画视图控制器吗? 尝试重新加载表上的数据。 【参考方案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;
];

【讨论】:

以上是关于当兄弟是 UIPageViewController 时,UITableView 没有动画的主要内容,如果未能解决你的问题,请参考以下文章

仅当样式设置为“滚动”时 UIPageViewController 中的约束异常

当 UIPageViewController 改变时改变 UINavigationController 的标题

UIPageViewController 和 UIButton 混合使用

uipageviewcontroller 中的 Swift uipageviewcontroller

在两页模式下如何实现可缩放的 UIPageViewController?

UIPageViewController 和 UIPageControl 透明背景颜色 - iOS