我想在我的网页浏览中添加一个捏合事件,并根据Xamarin文档添加:
PinchGestureRecognizer pinch = new PinchGestureRecognizer();
pinch.PinchUpdated += ClearCache;
webview.GestureRecognizers.Add(pinch);
然而,事件并未触发。我还需要做些什么才能让它发挥作用吗?
这是一种更加混乱的散射枪方法,我遇到的所有解决方案都无效:
public class SettingsPage : ContentPage {
ICommand tapCommand;
public SettingsPage() {
var url = Path.Combine(DependencyService.Get<IBaseUrl>().Get(), "index.html");
WebView webview = new WebView() {
Source = new UrlWebViewSource { Url = url },
WidthRequest = 1000,
HeightRequest = 1000
};
//webview.Navigating += ClearCache; ********THIS WORKS*********
Padding = Device.OnPlatform<Thickness>(
new Thickness(1, 20, 1, 1),
new Thickness(1),
new Thickness(1)
);
PinchGestureRecognizer pinch = new PinchGestureRecognizer();
pinch.PinchUpdated += ClearCache;
webview.GestureRecognizers.Add(pinch);
tapCommand = new Command(OnTapped);
TapGestureRecognizer tap = new TapGestureRecognizer { NumberOfTapsRequired = 3 };
tap.Tapped += ClearCache;
tap.SetBinding(TapGestureRecognizer.CommandProperty, "TapCommand");
tap.Command = tapCommand;
webview.GestureRecognizers.Add(tap);
StackLayout stackLayout = new StackLayout { Spacing = 0 };
stackLayout.Children.Add(webview);
stackLayout.Children.Add(btnClearCache);
View parent = (View)webview.ParentView;
parent.GestureRecognizers.Add(tap);
parent.GestureRecognizers.Add(pinch);
Content = webview;
}
private void OnTapped(object obj) {
var service = DependencyService.Get<IPlatformService>();
service.ClearWebViewCache();
}
private void ClearCache(object sender, EventArgs e) {
var service = DependencyService.Get<IPlatformService>();
service.ClearWebViewCache();
}
public ICommand TapCommand {
get { return tapCommand; }
}
答案 0 :(得分:2)
您可以使用MR.Gestures来处理iOS,Android和WinPhone 8.0 Silverlight上的向下和向上手势。对于Win Phone 8.1 / WinRT,我还没有找到方法。 如果您只需要iOS和Android,那么所有手势都可以在WebView上运行。