The decision on whether the image should disappear or simply return to its original state is triggered in the PanCompleted() method. Here, we wire up the two methods that we created in the previous two sections. Proceed as follows:
- Open Controls/SwiperControl.xaml.cs.
- Add the following code in bold to the PanCompleted() method:
private void PanCompleted()
{
if (CheckForExitCriteria())
{
Exit();
}
likeStackLayout.Opacity = 0;
denyStackLayout.Opacity = 0;
photo.TranslateTo(0, 0, 250, Easing.SpringOut);
photo.RotateTo(_initialRotation, 250, Easing.SpringOut);
photo.ScaleTo(1, 250);
}
The last step in this section is to use the CheckForExitCriteria() method, and the Exit() method if those criteria are met. If the exit criteria are not met, we need to reset the state and the opacity of the StackLayout to make everything go back to normal.