gpt4 book ai didi

ios - iOS 11.1.2 上的 Xamarin.Forms : Webview loads a bigger font

转载 作者:可可西里 更新时间:2023-11-01 04:32:52 27 4
gpt4 key购买 nike

我正在使用 Xamarin.Forms 加载互联网网页(客户的要求,请不要评判我),问题是在 iOS 中网页看起来比实际更大。

我在 iOS 上没有任何自定义渲染。

这是在 iPhone 6 iOS 11.1.2 的 safari 上加载的网站

这里是在 webview 上加载的

主页.xaml

<?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:Juppie"
x:Class="Juppie.MainPage">
<Grid>

<WebView x:Name="Navegador" Source="http://empleosapp.caonainteractive.com/"
WidthRequest="1000" HeightRequest="1000" IsVisible="{Binding Path=HayInternet}" ></WebView>
<ActivityIndicator IsRunning="{Binding Path=Navegando}" IsVisible="{Binding Path=Navegando}"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=0.33}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=0.33}"/>
</Grid>


</ContentPage>

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Plugin.Connectivity;
using System.ComponentModel;

namespace Juppie
{
public partial class MainPage : ContentPage, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

public MainPage()
{
InitializeComponent();

Navegador.Navigating += Navegador_Navigating;
Navegador.Navigated += (sender, e) => { Navegando = false; };
HayInternet = true;
BindingContext = this;
}
bool hayInternet;

public bool HayInternet
{
get
{
return hayInternet;
}

set
{
hayInternet = value;

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HayInternet"));

EvaluarInternet();
}
}
bool navegando;

public bool Navegando
{
get
{
return navegando;
}

set
{
navegando = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Navegando"));

}
}

public async void EvaluarInternet(){
if (!HayInternet)
{
await DisplayAlert("Aviso","Se requiere conexion a internet para emplear esta aplicacion", "OK");
}
}

protected override void OnAppearing()
{
HayInternet = CrossConnectivity.IsSupported && CrossConnectivity.Current.IsConnected;

CrossConnectivity.Current.ConnectivityChanged += (sender, args) =>
{
HayInternet = args.IsConnected;
};

base.OnAppearing();
}

protected override bool OnBackButtonPressed()
{
if (Navegador.CanGoBack)
{
Navegador.GoBack();
return false;
}

return base.OnBackButtonPressed();
}

void Navegador_Navigating(object sender, WebNavigatingEventArgs e)
{
Navegando = true;
if (e.Url.Contains("/banner"))
{
e.Cancel = true;

var uri = new Uri(e.Url.Replace("/banner", ""));
Device.OpenUri(uri);
}
}
}
}

我尝试使用自定义渲染并设置 scalePageToFit = false,但没有成功。如果有人知道我该如何解决这个问题,请告诉我。

最佳答案

Xaml:- VerticalOptions="FillAndExpand" 似乎满足 WebView 的 HeightRequest 和 WidthRequest 属性规范要求在 StackLayout 中呈现 - 在 Grid 中它似乎无论如何都会呈现:

<Grid>
<WebView x:Name="webView"
VerticalOptions="FillAndExpand"
Source="https://www.xamarin.com/"/>
</Grid>

渲染器,ScalesPageToFit 默认为 false(至少在 iPhone SE 11.2 的模拟器中是这样)

[assembly: ExportRenderer(typeof(WebView), typeof(MyWebViewRenderer))]
namespace MyNamespace.iOS
{
public class MyWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);

if (NativeView != null && e.NewElement != null)
{
var webView = ((UIWebView)NativeView);
webView.ScalesPageToFit = true;
}
}
}
}

下面的屏幕截图来自 iPhone SE 的模拟器。

ScalesPageToFit = true:

enter image description here

ScalesPageToFit = false: enter image description here

关于ios - iOS 11.1.2 上的 Xamarin.Forms : Webview loads a bigger font,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47655632/

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