在屏幕旋转事件上调整Xamarin.Forms核心库中定义的WebView

Ale*_*akh 5 webview xamarin.ios xamarin xamarin.forms

我在核心库中定义了网页作为填充整个屏幕的视图:

Content = new WebView
{
    VerticalOptions = LayoutOptions.FillAndExpand,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Source = "https://google.com",
};
Run Code Online (Sandbox Code Playgroud)

不幸的是在屏幕上旋转它没有调整大小(请参见下文):

在此输入图像描述 在此输入图像描述

如何确保在屏幕旋转时调整屏幕大小.

Dan*_*rda 5

如果是iOS,则制作自定义WebView渲染器(http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/):

protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
    base.OnElementChanged(e);

    AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
    ScalesPageToFit = true;
}

public override void LayoutSubviews()
{
    base.LayoutSubviews();

    NativeView.Bounds = UIKit.UIScreen.MainScreen.Bounds;
}
Run Code Online (Sandbox Code Playgroud)


小智 2

请尝试此解决方案,它适用于 iOS 8.4,但不适用于 iOS 7。 Xamarin Forms:如何在 iOS 中旋转后调整 Webview 的大小