xamarin - 平移手势导致闪烁问题
问题描述
我正在使用平移手势在 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);
编辑问题:
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);
解决方案
推荐阅读
- java - KeyListener 和 ActionListener 未注册
- javascript - 是否可以为 React 组件实现类似继承的机制以减少几乎重复的代码?
- autohotkey - 不确定为什么 AHK 脚本没有按预期工作
- jenkins - 詹金斯 - 文件夹上的权限被拒绝
- javascript - Vue3在按钮单击时以编程方式创建组件实例
- docker-compose - 本地开发微服务、方法和工具以高效工作
- c - 将算术运算符存储在C中的数组中?
- javascript - 仅在生产中动态导入文件以产生副作用
- reporting-services - SSRS - 对存在条件的列求和
- amazon-web-services - Cloudfront Hit 用于默认行为,但 'MISS' 用于路径模式