Skip to content

Instantly share code, notes, and snippets.

@matsukurou
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsukurou/daa7ef2c240c3501c948 to your computer and use it in GitHub Desktop.
Save matsukurou/daa7ef2c240c3501c948 to your computer and use it in GitHub Desktop.
Xamarin.Formsでビューに移動アニメーションを設定する
{
#region アニメーション用のボックスの生成
// 移動値算出用のボックスを生成
var boxViewBackground = new BoxView
{
Color = Color.Transparent,
};
// 前面アニメーション用のボックスを生成
var boxViewFront = new BoxView
{
Color = Color.Blue,
};
// 背面アニメーション用のボックスを生成
var boxViewBack = new BoxView
{
Color = Color.Red,
};
#endregion
#region アニメーション制御用のボタン類の設定
// 移動アニメーション制御用のボタンを生成
var buttonMove = new Button
{
Text = "Animation",
};
// ボタン押し時の挙動
buttonMove.Clicked += (sender, e) =>
{
var box = boxViewBackground;
// 下降アニメーション用のレクタングル
var moveDownRect = new Rectangle(0, box.Y + box.Height, box.Width, box.Height);
// 上昇アニメーション用のレクタングル
var moveUpRect = new Rectangle(0, box.Y, box.Width, box.Height);
if (boxViewFront.Y == boxViewBackground.Y)
{
// 現在のレイアウトから指定のレイアウトにアニメーションさせる
// ここではRectangleのサイズを変更していないので、単なる下方への移動アニメーション
boxViewFront.LayoutTo(moveDownRect);
}
else
{
// 現在のレイアウトから指定のレイアウトに、指定時間かけてボックスをアニメーションさせる
// ここではRectangleのサイズを変更していないので、単なる上方への移動アニメーション
boxViewFront.LayoutTo(moveUpRect, 1000);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment