【发布时间】:2018-12-24 18:04:13
【问题描述】:
我需要在 Xamarin.Form 应用程序中放大/缩小图像。 我的问题是,当我用捏合手势缩小图像时,它开始滞后并在整个显示屏上闪烁。相反,放大效果很好。 我已经遵循了官方指南 (https://docs.microsoft.com/it-it/xamarin/xamarin-forms/app-fundamentals/gestures/pinch) 和任何形式的论坛/社区,但我无法找到有效的答案。 有人可以帮我吗? 我在这里复制/粘贴代码部分。我本地化了我尝试设置 currentScale 变量的错误。
注意:我在类中有其他方法,但它们不管理图像或相关属性,因此我不复制/粘贴它们。
public partial class ResizeFoto : ContentPage
{
double currentScale = 1;
double startScale = 1;
double minScale = 0;
double maxScale = 2.5;
private void PinchGestureRecognizer_PinchUpdated(object sender,PinchGestureUpdatedEventArgs e){
switch (e.Status)
{
case GestureStatus.Started:
startScale = imgUserFoto.Scale;
break;
case GestureStatus.Running:
// LAS test 4
//Input gesture:
//Definition: "The distance between the user's digits, divided by the
//last reported distance between the user's digits in the pinch gesture"
// --> ZOOM IN = e.Scale > 1
// --> ZOOM OUT = e.Scale < 1
//ZOOM IN --> works good
if (e.Scale > 1)
{
currentScale += (e.Scale - 1) * startScale;
currentScale = Math.Min(currentScale, maxScale);
imgUserFoto.Scale = currentScale;
}
//ZOOM OUT --> not working, bug
else if (e.Scale < 1)
{
//HERE MAYBE THE BUG
currentScale = minScale + (e.Scale - 1) * startScale;
//also tried: currentScale = (e.Scale - 1) * startScale;
currentScale = Math.Max(minScale, currentScale);
imgUserFoto.Scale = currentScale;
}
}
break;
case GestureStatus.Completed:
break;
}
}
}
【问题讨论】:
-
visual-studio标签适用于与 Visual Studio 应用程序相关的问题,而不是您使用它创建的代码。
标签: c# xamarin xamarin.forms