0

私は Xamarin studio を使用しており、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 ();
4

2 に答える 2

-5

私は次のことで私が望んでいたことを達成することができました:

_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 ();
于 2013-10-21T08:21:23.170 に答える