2

我使用 AutoLayout 显示了 3 个 UIView。

  1. UIL标签
  2. UIView 用于浏览日历。此视图是一个自定义 UIView,其中包含一个 UIView,该 UIView 又包含两个 UIButton 和几个 UILabel
  3. 约会的 UiTableView

视图 2 有一个约束,其顶部等于视图 1 的底部 视图 3 有一个约束,其顶部等于视图 2 的底部

非常简单的东西,下面是一张图片,显示了 View 2 的 Constraint 上的常量被动画化。

在此处输入图像描述

问题是视图 3 立即占据其最终位置。为什么在动画过程中它没有保持在 View 2 的底部?

黑色空间是最终将由当前动画视图 2 填充的未着色区域

我正在使用 Monotouch,执行动画的代码是

// calendarDateBrowseYConstraint Is View 2
this.calendarDateBrowseYConstraint.Constant = value;

UIView.Animate(
    5.25f,
    0.0f,
    UIViewAnimationOptions.TransitionFlipFromBottom,
    () =>
    {
        this.calendarDateBrowse.LayoutIfNeeded();
    },
    null);
4

2 回答 2

4

LayoutIfNeeded()如果在容器视图上,请确保调用布局。您没有提到您的视图层次结构,但我假设您有类似的东西:

ViewController:
-view
---myContainerView
------label
------viewWithCalendar
------viewWithTableViewOrTableView

这是正确的调用动画的正确方法是(首先是简单的动画):

this.calendarDateBrowseYConstraint.Constant = value;
UIView.animateWithDuration(durationTime) {
    myContainerView.layoutIfNeeded()
}

你的呢:

this.calendarDateBrowseYConstraint.Constant = value; UIView.Animate(
    5.25f,
    0.0f,
    UIViewAnimationOptions.TransitionFlipFromBottom,
    () =>
    {
        myContainerView.LayoutIfNeeded();
    },
    null);
于 2015-09-17T09:24:13.673 回答
0

参考主视图编写LayoutIfNeeded()参考并确保动画没有在后台执行。

于 2015-09-12T05:41:55.107 回答