简体   繁体   中英

Sibling of animated UIView goes immediately to Final position

I have 3 UIViews displayed using AutoLayout.

  1. UILabel
  2. UIView for browsing a calendar. This view is a custom UIView containing a UIView which is in turn containing two UIButtons and a couple of UILabels
  3. UiTableView of Appointments

View 2 has a constraint that is positioning its Top Equal to View 1's Bottom View 3 has a constraint that is positioning its Top Equal to View 2's Bottom

Pretty simple stuff, below is a picture showing the Constant on View 2's Constraint being animated.

在此处输入图片说明

The problem is that View 3 takes its final position immediately. Why does it not stay positioned to the Bottom of View 2 during the animation?

The black space is the uncoloured area that will finally filled by the currently animating View 2

I am using Monotouch and the code to perform the Animation is

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

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

Be sure that you call layout if LayoutIfNeeded() on a container view. You didn't mention your view hierarchy but i assume you have something like that:

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

Is that correct the proper way to call your animation is (for simple animation first):

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

And yours:

this.calendarDateBrowseYConstraint.Constant = value; UIView.Animate(
    5.25f,
    0.0f,
    UIViewAnimationOptions.TransitionFlipFromBottom,
    () =>
    {
        myContainerView.LayoutIfNeeded();
    },
    null);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM