gpt4 book ai didi

xamarin 形成可缩放图像(跨平台)

转载 作者:行者123 更新时间:2023-12-01 15:02:11 29 4
gpt4 key购买 nike

有没有办法使用捏合来放大共享的Xamarin Forms,我只找到了每个平台的实现。

最佳答案

您可以使用 Pan Gesture 来实现它。这里有一个很好的在 PanContainer 中包装图像的示例 - Adding a Pan Gesture Recognizer .

The pan gesture is used for detecting dragging and is implemented with the PanGestureRecognizer class. A common scenario for the pan gesture is to horizontally and vertically drag an image, so that all of the image content can be viewed when it's being displayed in a viewport smaller than the image dimensions. This is accomplished by moving the image within the viewport.

简单的例子:

<Image Source="MonoMonkey.jpg">
<Image.GestureRecognizers>
<PanGestureRecognizer PanUpdated="OnPanUpdated" />
</Image.GestureRecognizers>
</Image>

Pan 容器示例 XAML:

<AbsoluteLayout>
<local:PanContainer>
<Image Source="MonoMonkey.jpg" WidthRequest="1024" HeightRequest="768" />
</local:PanContainer>
</AbsoluteLayout>

代码隐藏:

public class PanContainer : ContentView
{
double x, y;

public PanContainer ()
{
// Set PanGestureRecognizer.TouchPoints to control the
// number of touch points needed to pan
var panGesture = new PanGestureRecognizer ();
panGesture.PanUpdated += OnPanUpdated;
GestureRecognizers.Add (panGesture);
}

void OnPanUpdated (object sender, PanUpdatedEventArgs e)
{
switch (e.StatusType) {
case GestureStatus.Running:
// Translate and ensure we don't pan beyond the wrapped user interface element bounds.
Content.TranslationX =
Math.Max (Math.Min (0, x + e.TotalX), -Math.Abs (Content.Width - App.ScreenWidth));
Content.TranslationY =
Math.Max (Math.Min (0, y + e.TotalY), -Math.Abs (Content.Height - App.ScreenHeight));
break;

case GestureStatus.Completed:
// Store the translation applied during the pan
x = Content.TranslationX;
y = Content.TranslationY;
break;
}
}
}

关于xamarin 形成可缩放图像(跨平台),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30024418/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com