本記事の概要
この記事ではアニメーションでなめらかに減速をさせる方法について説明します。
公式サイト情報はコチラを参照してください。
なめらかに減速する
アニメーションをなめらかに減速させるには、イージング関数の Easing.SinOut を使用します。
アニメーションメソッドの TranselateToや RotateTo などさまざまなメソッドで使用することができます。
以下は START ボタンをクリックすると4秒掛けて右方向 200 の位置に移動するアニメーションが実行されます。SinOut を使用することでアニメーションはなめらかに減速します。
C# の例
private async void myButton_Clicked(object sender, EventArgs e) { await myImage.TranslateTo(200, 0, 4000, Easing.SinOut); }
XAML の例
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MauiAppSample.MainPage"> <ScrollView> <VerticalStackLayout> <Button Text="START" Clicked="myButton_Clicked"/> <Image x:Name="myImage" Source="excel.png" WidthRequest="128" HeightRequest="128"/> </VerticalStackLayout> </ScrollView> </ContentPage>
.NET MAUI Tips
本サイトでまとめている .NET MAUI Tips の一覧はこちらから確認できます。
Please follow and like us:
コメント