是否可以关闭 QLPreviewController 上的复制文本
Is it possible to closing copy text on QLPreviewController
我开发 Xamarin Forms 应用程序。我将 QLPreviewController 用于 ios。如果文档有文本,我想关闭复制 text/text 共享。这可能吗?如何?我搜索它是本地的。一些来源将我重定向到 UIDocumentInteractionControllerDelegate。但是我不明白我该怎么做。
提前致谢。
编辑:
我的 UIDocumentInteractionController 实现:
var firstController = UIApplication.SharedApplication.KeyWindow.RootViewController.ChildViewControllers.First().ChildViewControllers.Last().ChildViewControllers.First();
var navcontroller = firstController as UINavigationController;
var uidic = UIDocumentInteractionController.FromUrl(new NSUrl(file, true));
uidic.Delegate = new DocInteractionController(navcontroller);
uidic.PresentPreview(true);
public class DocInteractionController : UIDocumentInteractionControllerDelegate
{
UINavigationController navigationController;
public DocInteractionController(UINavigationController _navigationController)
{
navigationController = _navigationController;
}
}
在您的情况下,最好使用 WebView 来预览 pdf 等文件。
形式
创建自定义网络视图
public class MyWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(MyWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
在Android项目中
using Android.Content;
using Android.Net.Http;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
using Android.Widget;
using App32;
using App32.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(MyWebView), typeof(CustomWebViewRenderer))]
namespace App32.Droid
{
public class CustomWebViewRenderer : WebViewRenderer
{
Context _context;
public CustomWebViewRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
Android.Webkit.WebView web_view = new Android.Webkit.WebView(_context);
web_view.LoadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url="+((MyWebView)Element).Uri);
SetNativeControl(web_view);
Control.Settings.JavaScriptEnabled = true;
}
}
}
}
在iOS项目中
using System;
using App32;
using App32.iOS;
using Foundation;
using ObjCRuntime;
using UIKit;
using WebKit;
using Xamarin.Forms.Platform.iOS;
[assembly: Xamarin.Forms.ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]
namespace App32.iOS
{
public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
{
WKWebView _wkWebView;
protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var config = new WKWebViewConfiguration();
_wkWebView = new WKWebView(Frame, config);
SetNativeControl(_wkWebView);
}
if(e.NewElement!=null)
{
var webview = Element as MyWebView;
var url = webview.Uri;
Control.LoadRequest(new NSUrlRequest(new NSUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=" + webview.Uri)));
}
}
}
}
在xaml
现在您可以在 xaml 中使用它(您可以打开一个包含 WebView 的新 ContentPage)
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<local:MyWebView Uri="https://www.pdfpdf.com/samples/Sample1.PDF"/>
</StackLayout>
我开发 Xamarin Forms 应用程序。我将 QLPreviewController 用于 ios。如果文档有文本,我想关闭复制 text/text 共享。这可能吗?如何?我搜索它是本地的。一些来源将我重定向到 UIDocumentInteractionControllerDelegate。但是我不明白我该怎么做。
提前致谢。
编辑: 我的 UIDocumentInteractionController 实现:
var firstController = UIApplication.SharedApplication.KeyWindow.RootViewController.ChildViewControllers.First().ChildViewControllers.Last().ChildViewControllers.First();
var navcontroller = firstController as UINavigationController;
var uidic = UIDocumentInteractionController.FromUrl(new NSUrl(file, true));
uidic.Delegate = new DocInteractionController(navcontroller);
uidic.PresentPreview(true);
public class DocInteractionController : UIDocumentInteractionControllerDelegate
{
UINavigationController navigationController;
public DocInteractionController(UINavigationController _navigationController)
{
navigationController = _navigationController;
}
}
在您的情况下,最好使用 WebView 来预览 pdf 等文件。
形式
创建自定义网络视图
public class MyWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(MyWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
在Android项目中
using Android.Content;
using Android.Net.Http;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
using Android.Widget;
using App32;
using App32.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(MyWebView), typeof(CustomWebViewRenderer))]
namespace App32.Droid
{
public class CustomWebViewRenderer : WebViewRenderer
{
Context _context;
public CustomWebViewRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
Android.Webkit.WebView web_view = new Android.Webkit.WebView(_context);
web_view.LoadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url="+((MyWebView)Element).Uri);
SetNativeControl(web_view);
Control.Settings.JavaScriptEnabled = true;
}
}
}
}
在iOS项目中
using System;
using App32;
using App32.iOS;
using Foundation;
using ObjCRuntime;
using UIKit;
using WebKit;
using Xamarin.Forms.Platform.iOS;
[assembly: Xamarin.Forms.ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]
namespace App32.iOS
{
public class MyWebViewRenderer : ViewRenderer<MyWebView, WKWebView>
{
WKWebView _wkWebView;
protected override void OnElementChanged(ElementChangedEventArgs<MyWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
var config = new WKWebViewConfiguration();
_wkWebView = new WKWebView(Frame, config);
SetNativeControl(_wkWebView);
}
if(e.NewElement!=null)
{
var webview = Element as MyWebView;
var url = webview.Uri;
Control.LoadRequest(new NSUrlRequest(new NSUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=" + webview.Uri)));
}
}
}
}
在xaml
现在您可以在 xaml 中使用它(您可以打开一个包含 WebView 的新 ContentPage)
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<local:MyWebView Uri="https://www.pdfpdf.com/samples/Sample1.PDF"/>
</StackLayout>