OGeek|极客世界-中国程序员成长平台

标题: ios - 动画 UIView 的 sibling 立即进入最终位置 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:35
标题: ios - 动画 UIView 的 sibling 立即进入最终位置

我使用 AutoLayout 显示了 3 个 UIView。

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

View 2 有一个约束,将其顶部定位为 View 1 的底部 View 3 有一个约束,将其顶部定位为 View 2 的底部

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

enter image description here

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

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

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

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

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



Best Answer-推荐答案


确保在 container View 上调用 layout if LayoutIfNeeded()。您没有提到您的 View 层次结构,但我假设您有类似的东西:

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);

关于ios - 动画 UIView 的 sibling 立即进入最终位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32434105/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4