有没有一种方法可以使用仅Xamarin.Forms控件来实现捏合缩放的控制。
我想在Xamarin.Forms控件中显示图像(WebView或Image或任何其他控件),并能够从应用程序中进行缩放。
有没有一种方法可以使用仅Xamarin.Forms控件来实现捏合缩放的控制。
我想在Xamarin.Forms控件中显示图像(WebView或Image或任何其他控件),并能够从应用程序中进行缩放。
this.WebView.Source = new HtmlWebViewSource { BaseUrl = URL, Html = html };
The html will be defined here.
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta name="viewport" content="width=device-width, initial-scale=0.25, maximum-scale=3.0 user-scalable=1">
<title></title>
<style>
body {
margin: 0 20px 0 0;
font-family: HelveticaNeue-Light, HelveticaNeue-UltraLight, Helvetica, Consolas, 'Courier New';
}
table {
width: 100%;
border: 1px outset;
border-color: #3c4142;
}
td {
font-size: 8px;
}
</style>
</head>
<body>
<img src="data:image/png;base64,YourBase64imagestringhere" style="width:100%" />
</body>
</html>
public abstract class BaseInteractiveGestureRecognizer : BindableObject, IInteractiveGestureRecognizer
{
public static readonly BindableProperty CommandProperty = BindableProperty.Create<BaseInteractiveGestureRecognizer, ICommand> ((b) => b.Command, null, BindingMode.OneWay, null, null, null, null);
public ICommand Command {
get {
return (ICommand)base.GetValue (BaseInteractiveGestureRecognizer.CommandProperty);
}
set {
base.SetValue (BaseInteractiveGestureRecognizer.CommandProperty, value);
}
}
public object CommandParameter {get;set;} // make bindable as above
public GestureState State { get;set;} // make bindable as above
public View SourceView{ get; set; }
public void Send ()
{
if (Command != null && Command.CanExecute (this)) {
Command.Execute (this);
}
}
}
public class PanGesture : BaseInteractiveGestureRecognizer
{
public uint MinTouches { get;set; } // make bindable
public uint MaxTouches { get;set; } // make bindable
// add whatever other properties you need here - starting point, end point, touch count, current touch points etc.
}
然后在iOS项目中:
public abstract class BaseInteractiveGestureRenderer : BindableObject,IGestureCreator<UIView>
{
public abstract object Create (IInteractiveGestureRecognizer gesture, Element formsView, UIView nativeView);
public static GestureState FromUIGestureState (UIGestureRecognizerState state)
{
switch (state) {
case UIGestureRecognizerState.Possible:
return GestureState.Possible;
case UIGestureRecognizerState.Began:
return GestureState.Began;
case UIGestureRecognizerState.Changed:
return GestureState.Update;
case UIGestureRecognizerState.Ended:
return GestureState.Ended;
case UIGestureRecognizerState.Cancelled:
return GestureState.Cancelled;
case UIGestureRecognizerState.Failed:
return GestureState.Failed;
default:
return GestureState.Failed;
}
}
}
using StatementsHere;
[assembly: ExportGesture (typeof(PanGesture), typeof(PanGestureRenderer))]
namespace YourNamespaceHere.iOS
{
public class PanGestureRenderer : BaseInteractiveGestureRenderer
{
public PanGestureRenderer () : base ()
{
}
#region IGestureCreator implementation
public override object Create (IInteractiveGestureRecognizer gesture, Element formsView, UIView nativeView)
{
PanGesture panGesture = gesture as PanGesture;
nativeView.UserInteractionEnabled = true;
UIPanGestureRecognizer panGestureRecognizer = null;
panGestureRecognizer = new UIPanGestureRecognizer (() => panGesture.Send());
}
}