Hi all. First of all, let me tell you I'm pretty new both with Xamarin and C#, so I may perfectly be asking something either trivial or that just can't be done. The thing is... I have a BoxView
in a page and I add a TapGestureRecognizer
to it. It works perfectly. But then I decide to animate the BoxView
so it scales to 0.7 and back to 1.0 and again to 0.7 and... same thing forever. It animates correctly, yes, but then I start losing a lot of taps on it. Let's please consider this code:
public class App : Application
{
BoxView box;
int times;
public App()
{
box = new BoxView
{
BackgroundColor = Color.Pink,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
HeightRequest = 100,
WidthRequest = 100
};
MainPage = new ContentPage
{
Content = box
};
//AnimateBox();
var tgr = new TapGestureRecognizer();
tgr.Tapped += BoxViewTapped;
box.GestureRecognizers.Add(tgr);
}
async void AnimateBox()
{
while (true) {
await box.ScaleTo(0.7, 200, Easing.SinInOut);
await box.ScaleTo(1.0, 200, Easing.SinInOut);
}
}
void BoxViewTapped(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("times tapped: " + ++times);
}
}
With the AnimateBox();
commented out, if I tap on the BoxView
20 times, I got 20 messages in my output console. As expected. With the animation code working, I lose half of the taps or so.
Does anyone know why exactly this happens and how to fix it?
Thank you very much for your time.