我正在使用Xamarin工作室并使用Xamarin.iOS开发iPad应用程序。
我正在针对c#文件中的布局约束插座设置一个常量值。
_myRightSpaceConstraint.Constant = 50;
为此常量设置动画,使其来自:
_myRightSpaceConstraint.Constant = 300;
到
_myRightSpaceConstraint.Constant = 50;
OR ,与上面类似,但没有指定起始常量是什么(300),而是我只需要在xib文件中设置它并将其设置为50。
这是否可以在Xamarin中执行此操作,如果有,是否有任何代码示例可以帮助我?
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 ();
这实际上将常量成功设置为50但没有动画。
我设法通过以下方式实现了我想要的目标:
_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 ();
以下几行是关键:
_myViewWithTheConstraint.LayoutIfNeeded ();
答案 0 :(得分:9)
作为LayoutIfNeeded()
的{{1}}操作的一部分,在受约束的视图上致电animations
:
UIView.Animate
答案 1 :(得分:-4)
我设法通过以下方式实现了我想要的目标:
_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 ();
以下几行是关键:
_myViewWithTheConstraint.LayoutIfNeeded ();