2

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.

enter image description here

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);
Pat Long - Munkii Yebee
  • 3,592
  • 2
  • 34
  • 68
  • show the code that does the animation – Fonix Sep 07 '15 at 08:25
  • Please tell what the views are, UILabels can behave in unexpected ways with autolayout defined animations. To find out if UILabels are causing a problem, replace them temporary with plain UIViews, and see of the animation works then. – Joride Sep 15 '15 at 06:52

2 Answers2

4

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);
Jakub
  • 13,712
  • 17
  • 82
  • 139
0

write the LayoutIfNeeded() in reference to the main view & be sure that animation is not being preformed in the background.

Mihawk
  • 581
  • 4
  • 12