Я работаю над Xamarin с помощью жеста панорамирования. ниже - исходный код, который я использую. пожалуйста, помогите мне с решением.
private double x, y;
var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += (s, e) => {
// Handle the pan
switch (e.StatusType)
{
case GestureStatus.Started:
break;
case GestureStatus.Running:
var newRectangle = new Xamarin.Forms.Rectangle(x+e.TotalX, y+e.TotalY, localVideoControl.Bounds.Width, localVideoControl.Bounds.Height);
localVideoControl.LayoutTo(newRectangle, easing: Easing.Linear);
break;
case GestureStatus.Completed:
break;
}
};
localVideoControl.GestureRecognizers.Add(panGesture);
EDITED Вопрос:
var panFactor = 4.5;
var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += (s, e) => {
// Handle the pan
switch (e.StatusType)
{
case GestureStatus.Started:
localVideoControl.LayoutTo(new Xamarin.Forms.Rectangle(e.TotalX * panFactor + 100, e.TotalY * panFactor + 100, 100, 100), easing: Easing.Linear);
break;
case GestureStatus.Running:
// localVideoControl.TranslationX = Math.Max(Math.Min(0, x + e.TotalX), -Math.Abs(localVideoControl.Bounds.Width - Application.Current.MainPage.Width));
// localVideoControl.TranslationY = Math.Max(Math.Min(0, y + e.TotalY), -Math.Abs(localVideoControl.Bounds.Height - Application.Current.MainPage.Height));
// var newRectangle = new Xamarin.Forms.Rectangle((e.TotalX * panFactor) +(localVideoControl.Bounds.Width), (e.TotalY * panFactor) +(localVideoControl.Bounds.Height), localVideoControl.Bounds.Width, localVideoControl.Bounds.Height);
// var newRectangle = new Xamarin.Forms.Rectangle(e.TotalX + 100 , (e.TotalY + 100) , localVideoControl.Bounds.Width, localVideoControl.Bounds.Height);
// localVideoControl.LayoutTo(newRectangle, easing: Easing.Linear);
// AbsoluteLayout.SetLayoutBounds(localVideoControl, new Xamarin.Forms.Rectangle(e.TotalX- 50, e.TotalY-50, 100, 100));
localVideoControl.LayoutTo(new Xamarin.Forms.Rectangle(e.TotalX * panFactor + 100, e.TotalY * panFactor + 100, 100, 100), easing: Easing.Linear);
if (localVideoControl.TranslationX <= 0 || e.TotalX < 100 )
{
AbsoluteLayout.SetLayoutBounds(localVideoControl, new Xamarin.Forms.Rectangle(0, 0, 100, 100));
}
if (localVideoControl.TranslationY <= 0 || e.TotalY < 100)
{
AbsoluteLayout.SetLayoutBounds(localVideoControl, new Xamarin.Forms.Rectangle(0, 0, 100, 100));
}
break;
case GestureStatus.Completed:
if (localVideoControl.TranslationX > (Application.Current.MainPage.Width - 100) )
{
localVideoControl.TranslationX = e.TotalX;
}
if (localVideoControl.TranslationY > (Application.Current.MainPage.Height - 100))
{
localVideoControl.TranslationY = e.TotalY;
}
if (localVideoControl.TranslationX <= 0 || e.TotalX < 100)
{
AbsoluteLayout.SetLayoutBounds(localVideoControl, new Xamarin.Forms.Rectangle(0, 0, 100, 100));
}
if (localVideoControl.TranslationY <= 0 || e.TotalY < 100)
{
AbsoluteLayout.SetLayoutBounds(localVideoControl, new Xamarin.Forms.Rectangle(0, 0, 100, 100));
}
break;
}
};
localVideoControl.GestureRecognizers.Add(panGesture);