Xamarin.ios Xamarin QLEVIEWCONTROLLER+;iOS 10上导航页面已断开
将设备更新到iOS 10后,QLViewController停止以正确显示文档。它显示白色屏幕。 我已经从应用程序中提取了示例场景 它包含一个页面,带有两个按钮,可以加载两个不同的文档:Xamarin.ios Xamarin QLEVIEWCONTROLLER+;iOS 10上导航页面已断开,xamarin.ios,xamarin.forms,quicklook,Xamarin.ios,Xamarin.forms,Quicklook,将设备更新到iOS 10后,QLViewController停止以正确显示文档。它显示白色屏幕。 我已经从应用程序中提取了示例场景 它包含一个页面,带有两个按钮,可以加载两个不同的文档: <?xml version="1.0" encoding="utf-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/win
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:QuickLookIOS10Test"
x:Class="QuickLookIOS10Test.QuickLookIOS10TestPage">
<StackLayout Orientation="Vertical">
<Button Text="Load first doc" Clicked="OnLoadFirstClicked"/>
<Button Text="Load second doc" Clicked="OnLoadSecondClicked"/>
<Button Text="Navigate forward" Clicked="OnForwardClicked"/>
<local:QLDocumentView
x:Name="DocumentView"
BackgroundColor="Silver"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"/>
</StackLayout>
</ContentPage>
涉及到一个自定义渲染器:
public class QLDocumentViewRenderer : ViewRenderer<QLDocumentView, UIView>
{
private QLPreviewController controller;
public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
//This is a fix to prevent incorrect scaling after rotating from portrait to landscape.
//No idea why does this work :( Bug #101639
return new SizeRequest(Size.Zero, Size.Zero);
}
protected override void OnElementChanged(ElementChangedEventArgs<QLDocumentView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
controller = new QLPreviewController();
SetNativeControl(controller.View);
}
RefreshView();
}
protected override void OnElementPropertyChanged(object sender,
System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == QLDocumentView.FilePathProperty.PropertyName)
{
RefreshView();
}
}
private void RefreshView()
{
DisposeDataSource();
if (Element?.FilePath != null)
{
controller.DataSource = new DocumentQLPreviewControllerDataSource(Element.FilePath);
}
controller.ReloadData();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
DisposeDataSource();
DisposeController();
}
}
private void DisposeDataSource()
{
var dataSource = controller.DataSource;
controller.DataSource = null;
dataSource?.Dispose();
}
private void DisposeController()
{
controller?.Dispose();
controller = null;
}
private class DocumentQLPreviewControllerDataSource : QLPreviewControllerDataSource
{
private readonly string fileName;
public DocumentQLPreviewControllerDataSource(string fileName)
{
this.fileName = fileName;
}
public override nint PreviewItemCount(QLPreviewController controller)
{
return 1;
}
public override IQLPreviewItem GetPreviewItem(QLPreviewController controller, nint index)
{
NSUrl url = NSUrl.FromFilename(fileName);
return new QlItem(url);
}
private sealed class QlItem : QLPreviewItem
{
private readonly NSUrl itemUrl;
public QlItem(NSUrl uri)
{
itemUrl = uri;
}
public override string ItemTitle { get { return string.Empty; } }
public override NSUrl ItemUrl { get { return itemUrl; } }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
this.itemUrl?.Dispose();
}
}
}
}
}
它可以在iOS 9.3上运行,但不能在iOS 10上运行。如果我删除NavigationPage:
MainPage = new QuickLookIOS10TestPage();
它适用于两个iOS版本
按钮单击背后的代码只是设置控件的FilePath属性
Xamarin表格2.3.2.127
Xamarin Studio 6.1.1(build 15)我也面临同样的问题。它看起来像iOS10中的QuickLook,但解决方案非常简单:
public class PdfViewerControlRenderer : ViewRenderer<PdfViewerControl, UIView>
{
private readonly bool IsOniOS10;
private UIViewController _controller;
private QLPreviewController _qlPreviewController;
public PdfViewerControlRenderer()
{
IsOniOS10 = UIDevice.CurrentDevice.CheckSystemVersion(10, 0);
}
protected override void OnElementChanged(ElementChangedEventArgs<PdfViewerControl> e)
{
if (e.NewElement != null)
{
_controller = new UIViewController();
_qlPreviewController = new QLPreviewController();
//...
// Set QuickLook datasource here
//...
if (!IsOniOS10)
{
_controller.AddChildViewController(_qlPreviewController);
_controller.View.AddSubview(_qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_controller);
}
SetNativeControl(_controller.View);
}
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
_controller.View.Frame = Bounds;
_controller.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
_qlPreviewController.View.Frame = Bounds;
if (IsOniOS10)
{
_controller.View.AddSubview(_qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_controller);
}
}
}
公共类PdfViewerControlRenderer:ViewRenderer
{
私有只读bool IsOniOS10;
专用UIViewController _控制器;
专用QLPreviewController\u QLPreviewController;
公共PdfViewerControlRenderer()
{
IsOniOS10=UIDevice.CurrentDevice.CheckSystemVersion(10,0);
}
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
if(例如NewElement!=null)
{
_控制器=新的UIViewController();
_QLEVIEWCONTROLLER=新的QLEVIEWCONTROLLER();
//...
//在此处设置QuickLook数据源
//...
如果(!IsOniOS10)
{
_controller.AddChildViewController(qlPreviewController);
_controller.View.AddSubview(qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_控制器);
}
SetNativeControl(_controller.View);
}
}
公共覆盖无效布局子视图()
{
base.LayoutSubviews();
_controller.View.Frame=边界;
_controller.View.AutoresizingMask=uiviewsautoresizing.FlexibleWidth | uiviewsautoresizing.FlexibleHeight;
_qlPreviewController.View.Frame=边界;
if(IsOniOS10)
{
_controller.View.AddSubview(qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_控制器);
}
}
}
结果:
我也面临同样的问题。它看起来像iOS10中的QuickLook,但解决方案非常简单:
public class PdfViewerControlRenderer : ViewRenderer<PdfViewerControl, UIView>
{
private readonly bool IsOniOS10;
private UIViewController _controller;
private QLPreviewController _qlPreviewController;
public PdfViewerControlRenderer()
{
IsOniOS10 = UIDevice.CurrentDevice.CheckSystemVersion(10, 0);
}
protected override void OnElementChanged(ElementChangedEventArgs<PdfViewerControl> e)
{
if (e.NewElement != null)
{
_controller = new UIViewController();
_qlPreviewController = new QLPreviewController();
//...
// Set QuickLook datasource here
//...
if (!IsOniOS10)
{
_controller.AddChildViewController(_qlPreviewController);
_controller.View.AddSubview(_qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_controller);
}
SetNativeControl(_controller.View);
}
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
_controller.View.Frame = Bounds;
_controller.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
_qlPreviewController.View.Frame = Bounds;
if (IsOniOS10)
{
_controller.View.AddSubview(_qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_controller);
}
}
}
公共类PdfViewerControlRenderer:ViewRenderer
{
私有只读bool IsOniOS10;
专用UIViewController _控制器;
专用QLPreviewController\u QLPreviewController;
公共PdfViewerControlRenderer()
{
IsOniOS10=UIDevice.CurrentDevice.CheckSystemVersion(10,0);
}
受保护的覆盖无效OnElementChanged(ElementChangedEventArgs e)
{
if(例如NewElement!=null)
{
_控制器=新的UIViewController();
_QLEVIEWCONTROLLER=新的QLEVIEWCONTROLLER();
//...
//在此处设置QuickLook数据源
//...
如果(!IsOniOS10)
{
_controller.AddChildViewController(qlPreviewController);
_controller.View.AddSubview(qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_控制器);
}
SetNativeControl(_controller.View);
}
}
公共覆盖无效布局子视图()
{
base.LayoutSubviews();
_controller.View.Frame=边界;
_controller.View.AutoresizingMask=uiviewsautoresizing.FlexibleWidth | uiviewsautoresizing.FlexibleHeight;
_qlPreviewController.View.Frame=边界;
if(IsOniOS10)
{
_controller.View.AddSubview(qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_控制器);
}
}
}
结果:
如果您认为这在iOS 9上曾经有效,而现在在iOS 10上不再有效,那么您可能应该在bugreport.apple.com上告诉他们!我仍然不知道是iOS、Xamarin还是我的渲染器代码问题。我不能用Swift和xcode复制它如果你认为它过去在iOS 9上工作,现在在iOS 10上不再工作了,你可能应该在bugreport.apple.com上让他们知道!我仍然不知道是iOS、Xamarin还是我的渲染器代码问题。我无法使用Swift和XCode复制它
public class PdfViewerControlRenderer : ViewRenderer<PdfViewerControl, UIView>
{
private readonly bool IsOniOS10;
private UIViewController _controller;
private QLPreviewController _qlPreviewController;
public PdfViewerControlRenderer()
{
IsOniOS10 = UIDevice.CurrentDevice.CheckSystemVersion(10, 0);
}
protected override void OnElementChanged(ElementChangedEventArgs<PdfViewerControl> e)
{
if (e.NewElement != null)
{
_controller = new UIViewController();
_qlPreviewController = new QLPreviewController();
//...
// Set QuickLook datasource here
//...
if (!IsOniOS10)
{
_controller.AddChildViewController(_qlPreviewController);
_controller.View.AddSubview(_qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_controller);
}
SetNativeControl(_controller.View);
}
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
_controller.View.Frame = Bounds;
_controller.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
_qlPreviewController.View.Frame = Bounds;
if (IsOniOS10)
{
_controller.View.AddSubview(_qlPreviewController.View);
_qlPreviewController.DidMoveToParentViewController(_controller);
}
}
}