Animation.commit возвращает обратный вызов до завершения анимации в формах Xamarin - PullRequest
0 голосов
/ 24 сентября 2018

Я делаю анимацию для игры в рулетку, это рулетка с 4 секторами.Я использую класс анимации и расширения анимации.Но проблема в том, что в методе animation.commit один из параметров должен возвращать конец анимации, потому что мне нужно сделать что-то еще после окончания анимации.Но проблема в том, что анимация заставляет код завершать работу до завершения полной анимации.Что я делаю не так?

Вот мой код:

'using FormsControls.Base;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

  namespace RouletteFish.Views
  {
       [XamlCompilation(XamlCompilationOptions.Compile)]
       public partial class RouletteGame : ContentPage
       {

    private bool _userTapped;
    private long lngDegrees = 0;
    private int degree = 0;
    private int degreeOld;
    private int finalDegree = 0;
    private int cantidadSectores = 4;
    private long alldegrees;
    private int half;
    private float gradePosition;


    public RouletteGame ()
    {
        InitializeComponent ();
        alldegrees = 360;
        cantidadSectores = 4;
        half = 2;
        gradePosition = 360 / 4 / 2;

    }

    private double width;
    private double height;


    private  void OnImageNameTapped(object sender, EventArgs args)
    {
        try
        {
            if (_userTapped)
                return;

            _userTapped = true;




            // Create parent animation object.
            Animation parentAnimation = new Animation();

            RotateRoulette();


            Animation rotation = new Animation(callback: d => imageRoulette.RotateTo(finalDegree * (360 / 6), 3600, Easing.Linear),
                                         start: degreeOld,
                                         end: finalDegree,
                                         easing: Easing.SpringOut);


            parentAnimation.Add(0, 1, rotation);


            // Commit parent animation
              parentAnimation.Commit(
                  this, "Animation1", 16, 250, null,
                  (v, c) => checkResult(v,c));


                   }
        catch (Exception ex)
        {
            throw ex;
        }
    }



    private  void RotateRoulette() {
        degreeOld = degree % 360;
        degree = new Random().Next(360) + 720;
        uint u = (uint)(int)new Random().Next(360) + 3600;
         finalDegree = degree;
        //imageRoulette.RotateTo(finalDegree * (360/6), 3600, Easing.Linear);

    }



    public void checkResult(double v, bool c) {
        Debug.WriteLine("parent finished: {0} {1}");
        DisplayAlert("Sector", getSector(360 - (finalDegree % 360)), "Ok");
        _userTapped = false;
    }

    private String getSector(int degrees)
    {
        int i = 0;
        String text = null;

        do
        {
            // start and end of each sector on the wheel
            float start = gradePosition * (i * 2 + 1);
            float end = gradePosition * (i * 2 + 3);

            if (degrees >= start && degrees < end)
            {
                // degrees is in [start;end[
                // so text is equals to sectors[i];
                text = prices[i];
            }

            i++;
            // now we can test our Android Roulette Game :)
            // That's all !
            // In the second part, you will learn how to add some bets on the table to play to the Roulette Game :)
            // Subscribe and stay tuned !

        } while (text == null && i < prices.Count());

        return text;
    }


}

  }'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...