gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:46:47 26 4
gpt4 key购买 nike

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

Content = new WebView
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
Source = "https://google.com",
};

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

enter image description here
enter image description here

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

最佳答案

如果是 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;
}

关于webview - 在屏幕旋转事件上调整 Xamarin.Forms 核心库中定义的 WebView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31594632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com