答案 0 :(得分: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;
}
答案 1 :(得分:2)
您需要使用Xamarin.forms。
使用webviewWorking with WebView in Xamarin.Forms
xamarin-forms-samples/WorkingWithWebview每个平台都有示例。
Handling Rotation上的此链接为您提供Android所需的所有详细信息。另一个答案涵盖了iOS。
Responding To Orientation Changes In Xamarin Forms另一个很棒的链接
Customizing Controls for Each Platform使用这些前提,您可以在一个应用中分别管理每个平台的屏幕旋转。
Handling Runtime Changes显示了如何管理屏幕旋转。您需要向下滚动页面。
管理Windows Phone The two ways to handle orientation in your Windows 8.1 app的良好链接。
另一个有用的链接Fix IE 10 on Windows Phone 8 Viewport。
这是来自mozilla的Managing screen orientation的有趣链接。这是实验性的,但很有趣。
答案 2 :(得分:1)
请尝试此解决方案,它适用于iOS 8.4,但不适用于iOS 7。 Xamarin Forms: How to resize the Webview after rotation in iOS
答案 3 :(得分:0)
我实现了自定义渲染器并添加了行" webView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;"但它对我不起作用。然后,我用一个不那么优雅的解决方案解决了这个问题(当设备方向改变时重新加载WebView组件)。
在我的xaml中:
<StackLayout Padding="0" >
<WebView x:Name="viewJupyter" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
</StackLayout>
我的代码在课后:
public partial class ServiceChart : ContentPage
{
private int _rotateView;
public ServiceChart(string title, string url)
{
Title = title;
InitializeComponent();
var urlPage = new UrlWebViewSource
{
Url = url
};
viewJupyter.Source = urlPage;
if (Device.OS == TargetPlatform.iOS)
{
SizeChanged += (sender, arg) =>
{
if (_rotateView != 0)
{
var lalala = viewJupyter;
InitializeComponent();
viewJupyter.Source = (lalala.Source as UrlWebViewSource).Url;
}
_rotateView++;
};
}
}
}