2016-11-30 18 views
0

Xamarin.Forms(バージョン2.3.3.168)でイメージをアニメートしようとしています。アニメーションは機能していますが、繰り返しはありません。数秒間のアプリを実行した後Xamarinフォームアニメーションが繰り返されない

public class WelcomePage : ContentPage 
{ 
    Image img; 

    public WelcomePage() 
    { 
     img = new Image 
     { 
      Source = "img.png", 
      HorizontalOptions = LayoutOptions.Center, 
      VerticalOptions = LayoutOptions.Center, 
     }; 

     Content = new StackLayout 
     { 
      VerticalOptions = LayoutOptions.Center, 
      Children = { 
       img 
      } 
     }; 
    } 

    protected override void OnAppearing() 
    { 
     base.OnAppearing(); 

     var a = new Animation(); 
     a.Add(0, 0.5, new Animation((v) => 
     { 
      img.Scale = v; 
     }, 1.0, 1.2, Easing.CubicInOut,() => { System.Diagnostics.Debug.WriteLine("ANIMATION A"); })); 
     a.Add(0.5, 1, new Animation((v) => 
     { 
      img.Scale = v; 
     }, 1.2, 1.0, Easing.CubicInOut,() => { System.Diagnostics.Debug.WriteLine("ANIMATION B"); })); 
     a.Commit(img, "animation", 16, 2000, Easing.Linear, (d, f) => img.Scale = 1.0,() => 
     { 
      System.Diagnostics.Debug.WriteLine("ANIMATION ALL"); 
      return true; 
     }); 
    } 
} 

、次のデバッグ出力が出力されます。

ANIMATION A 
ANIMATION B 
ANIMATION ALL 
ANIMATION ALL 
ANIMATION ALL 

私はUWPとしてこれをテストしています。

答えて

1

this thread on the Xamarin forumsによると、他にも同じ問題があるようです。サブアニメーションのそれぞれにプライベートプロパティが設定されているようです。

問題を回避するには、アニメーションのチェーンをチェーンが完了するたびに再作成することである。

public class WelcomePage : ContentPage 
{ 
    Image img; 

    public WelcomePage() 
    { 
     img = new Image 
     { 
      Source = "circle_plus.png", 
      HorizontalOptions = LayoutOptions.Center, 
      VerticalOptions = LayoutOptions.Center, 
     }; 

     Content = new StackLayout 
     { 
      VerticalOptions = LayoutOptions.Center, 
      Children = { 
       img 
      } 
     }; 
    } 

    protected override void OnAppearing() 
    { 
     base.OnAppearing(); 
     animate(); 
    } 

    void animate() 
    { 
     var a = new Animation(); 
     a.Add(0, 0.5, new Animation((v) => 
     { 
      img.Scale = v; 
     }, 1.0, 1.2, Easing.CubicInOut,() => { System.Diagnostics.Debug.WriteLine("ANIMATION A"); })); 
     a.Add(0.5, 1, new Animation((v) => 
     { 
      img.Scale = v; 
     }, 1.2, 1.0, Easing.CubicInOut,() => { System.Diagnostics.Debug.WriteLine("ANIMATION B"); })); 
     a.Commit(img, "animation", 16, 2000, null, (d, f) => 
     { 
      img.Scale = 1.0; 
      System.Diagnostics.Debug.WriteLine("ANIMATION ALL"); 
      animate(); 
     }); 
    } 
} 
関連する問題