Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimate a layout constraint constant from one value to another using Xamarin.ios
    text
    copied!<p>I am using Xamarin studio and developing an iPad app with Xamarin.iOS.</p> <p>I am setting a constant value against a layout constraint outlet in my c# file.</p> <h2>What I have at the moment (no animations)</h2> <pre><code>_myRightSpaceConstraint.Constant = 50; </code></pre> <h2>What I want</h2> <p>Animate this constant so that it goes from:</p> <pre><code>_myRightSpaceConstraint.Constant = 300; </code></pre> <p>to</p> <pre><code>_myRightSpaceConstraint.Constant = 50; </code></pre> <p><strong>OR</strong>, similar to above but don't specifiy what the start constant is (300), instead I just take whatever it is set to in the xib file and animate to 50.</p> <p>Is this possible to do this in Xamarin and if so are there any code examples to help me?</p> <h2>What I have tried - which doesnt work</h2> <pre><code>UIView.BeginAnimations ("slideAnimation"); float _pt; _pt = _myRightSpaceConstraint.Constant; UIView.SetAnimationDuration (5); UIView.SetAnimationCurve (UIViewAnimationCurve.EaseInOut); UIView.SetAnimationDelegate (this); UIView.SetAnimationDidStopSelector ( new Selector ("slideAnimationFinished:")); _myRightSpaceConstraint.Constant = 50; UIView.CommitAnimations (); </code></pre> <p>This actually sets the constant successfully to 50 but with no animation.</p> <h2>Edit/Update:</h2> <p>I managed to achieve what I wanted with the following:</p> <pre><code>_myRightSpaceConstraint.Constant = 150; _myViewWithTheConstraint.SetNeedsUpdateConstraints (); UIView.BeginAnimations ("slideAnimation"); UIView.SetAnimationDuration (1); UIView.SetAnimationCurve (UIViewAnimationCurve.EaseInOut); UIView.SetAnimationDelegate (this); UIView.SetAnimationDidStopSelector ( new Selector ("slideAnimationFinished:")); _myViewWithTheConstraint.LayoutIfNeeded (); UIView.CommitAnimations (); </code></pre> <p>The following line was the key:</p> <pre><code>_myViewWithTheConstraint.LayoutIfNeeded (); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload