public AnimationsSample()
        {
            var button = new Button
            {
                Text = "Animate",
            };

            var box = new BoxView
            {
                WidthRequest = 100,
                HeightRequest = 100,
                Color = Color.Red,
                HorizontalOptions = LayoutOptions.Center,
            };


            var stack = new StackLayout
            {
                Padding = 10,
                Spacing = 10,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children =
                {
                    button,
                    box
                }
            };
            this.Content = stack;

            button.Clicked += async (s, e) =>
            {
                button.IsEnabled = false;
                box.Color = Color.Green;

                var original = box.Bounds;
                var newPosition = box.Bounds;
                newPosition.Y = this.Height - box.Height;
                await box.LayoutTo(newPosition, 2000, Easing.BounceOut);

                await box.FadeTo(0, 2000);
                box.Color = Color.Yellow;
                box.ScaleTo(2, 2000);
                await box.FadeTo(1, 2000);
                box.ScaleTo(1, 2000);
                box.Color = Color.Green;
                await box.LayoutTo(original, 2000, Easing.Linear);
                box.Color = Color.Red;
                button.IsEnabled = true;
            };
        }
Beispiel #2
0
        public Page1()
        {
            this.SizeChanged += async delegate(object sender, EventArgs e) {
                MenuManager ();

                var hGrid = this.Height - 100;
                //g.HeightRequest = hGrid;
                //menu1.Height = hGrid;
                boxmenu1.HeightRequest = hGrid / 2;
                boxmenu1B.HeightRequest = hGrid / 2;
            };

            g = new Grid (){ /*VerticalOptions = LayoutOptions.FillAndExpand*/ };
            g.RowSpacing = 0;
            g.SizeChanged += async delegate(object sender, EventArgs e) {
                return;
            };
            menu3 = new RowDefinition ();
            menu3.Height = new GridLength (100, GridUnitType.Absolute);
            g.RowDefinitions.Add (menu3);

            menu2 = new RowDefinition ();
            menu2.Height = new GridLength (100, GridUnitType.Absolute);
            g.RowDefinitions.Add (menu2);

            menu1 = new RowDefinition ();
            menu1.Height = new GridLength (100, GridUnitType.Absolute);
            g.RowDefinitions.Add (menu1);

            boxmenu3 = new BoxView ();
            boxmenu3.BackgroundColor = Color.Red;
            g.Children.Add (boxmenu3);
            Grid.SetRow (boxmenu3, 0);

            boxmenu2 = new BoxView ();
            boxmenu2.BackgroundColor = Color.Blue;
            g.Children.Add (boxmenu2);
            Grid.SetRow (boxmenu2, 1);
            var tapGestureRecognizer2 = new TapGestureRecognizer ();
            //tapGestureRecognizer.SetBinding (TapGestureRecognizer.CommandProperty, "Animate");
            boxmenu2.GestureRecognizers.Add (tapGestureRecognizer2);
            tapGestureRecognizer2.Tapped += async delegate(object sender, EventArgs e) {
                await boxmenu2.ScaleTo (3, 10);
            };

            boxmenu1 = new BoxView (){ VerticalOptions = LayoutOptions.End };
            boxmenu1.BackgroundColor = Color.Yellow;
            g.Children.Add (boxmenu1);
            Grid.SetRow (boxmenu1, 2);
            var tapGestureRecognizer1 = new TapGestureRecognizer ();
            boxmenu1.GestureRecognizers.Add (tapGestureRecognizer1);
            tapGestureRecognizer1.Tapped += async delegate(object sender, EventArgs e) {
                //menu2IsVisible = true;
                //MenuManager ();
                //await boxmenu2.Animate( ();
                boxmenu1B.IsVisible = true;
                var hGrid = this.Height - 100;
                g.HeightRequest = hGrid;
                menu1.Height = hGrid;
                boxmenu1.HeightRequest = hGrid / 2;
                boxmenu1B.HeightRequest = hGrid / 2;
                await boxmenu1B.TranslateTo (0, -(hGrid / 2), 1000);
            };

            boxmenu1B = new BoxView (){ VerticalOptions = LayoutOptions.End };
            boxmenu1B.BackgroundColor = Color.Pink;
            boxmenu1B.IsVisible = false;
            g.Children.Add (boxmenu1B);
            Grid.SetRow (boxmenu1B, 2);

            Button b = new Button ();
            b.Text = "pag2";
            b.Clicked += async delegate(object sender, EventArgs e) {
                Navigation.PushAsync (new Page2 (), true);
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.EndAndExpand,
                Children = {
                    g
                    /*
                    new Label { Text = "Hello ContentPage1" },
                    b,
                    */

                }
            };
        }
		public MultiAnimationPage()
		{
			#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);
				}
			};

			// 拡大縮小アニメ制御用のボタンを生成
			var buttonScale = new Button
			{
				Text = "Scale",
			};
			// ボタン押し時の挙動
			buttonScale.Clicked += (sender, e) => 
			{
				if (boxViewFront.Scale == 1)
				{
					// ボックスのスケールが1だった場合
					// 指定秒かけてScaleを0にする
					boxViewFront.ScaleTo(0, 500);
				}
				else
				{
					// ボックスのスケールが0だった場合
					// 指定秒かけてScaleを1にする
					boxViewFront.ScaleTo(1, 1000);
				}
			};

			// 回転アニメ制御用のボタンを生成
			var buttonRelRotate = new Button
			{
				Text = "RelRotate",
			};
			// ボタン押し時の挙動
			buttonRelRotate.Clicked += (sender, e) => 
			{
				// ボタンが押されるたびにボックスを30度ずつ回転させる
				boxViewFront.RelRotateTo(30, 500);
			};				
			#endregion

			#region レイアウト関連
			// ボタン用のレイアウト
			var stack = new StackLayout
			{
				Children = 
				{
					buttonMove,
					buttonScale,
					buttonRelRotate,
				},
			};

			// ページ全体のレイアウト用のグリッドを生成
			var grid = new Grid
			{
				// 画面縦いっぱいに表示する
				VerticalOptions = LayoutOptions.FillAndExpand,

				RowDefinitions =
				{
					new RowDefinition { Height = GridLength.Auto },
					new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
				},
			};
			// グリッドにパーツを設定
			grid.Children.Add(stack, 0, 0);
			grid.Children.Add(boxViewBackground, 0, 1);
			grid.Children.Add(boxViewBack, 0, 1);
			grid.Children.Add(boxViewFront, 0, 1);

			// ページのコンテントにグリッドを設定
			Content = grid;
			#endregion
		}