2017-12-05 11 views
5

私はXamarin.Formsを使用してインターネットのWebページを読み込みます(クライアントの要件、私を判断しないでください)。問題はiOSでウェブページはそれよりも大きく見えます。iam 11.1.2のXamarin.Forms:Webviewがより大きなフォントを読み込む

iOSではカスタムレンダリングがありません。ここで

はiPhone 6のiOS 11.1.2

のSafariにロードされたウェブサイトであり、ここでのWebView

MainPage.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> 

メインページにロードされています。 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を設定しました。これは成功しませんでした。 どうすればこの問題を解決できるか分かっている場合は、教えてください。

+1

私はSafariでスクロールすると、それはズームを保持します。 –

答えて

2

私のiPhone 6でテストし、アプリはSafariと同じサイズのフォントを表示していました。 私はまた、アプリのフォントサイズで大きなシステムフォントでテストしましたが、アプリのフォントサイズには影響されませんでした。 しかし、私は、アクティビティインジケータが実行されているときに、フォントサイズが小さくなり、アクティビティインジケータが消えた後に正常になったことに気付きました。

多分、フォントサイズの問題は、Nugetパッケージやアクティビティインジケータのような追加の副作用によって引き起こされたのでしょうか?

新しい空のフォームを使用してWebビューのみを読み込んで、違いを比較することができます。

ところで、あなたのアプリの外観は、iPhoneのディスプレイズーム機能をオンにした場合と非常に似ています。拡大表示をオンにする前

enter image description here

拡大表示をオンにした後:

enter image description here

+0

私は、このパッケージを使用しています: Microsoft.Azure.Mobile Microsoft.Azure.Mobile.Analytics Microsoft.Azure.Mobile.Crashes Microsoft.Azure.Mobile.Distribute Microsoft.Azure.Mobile.Push Xam.Plugin.Connectivity Xamarin.Forms –

3

XAML: - VerticalOptions="FillAndExpand"はStackLayoutにレンダリングするHeightRequestを満たしているようだとWebViewためWidthRequestプロパティの仕様要件 - とにかくレンダリングするようだグリッドで:

<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 =真:偽

enter image description here

ScalesPageToFit =: enter image description here

+1

http://empleosapp.caonainteractive.com/で何か変なことがありますが、何らかの理由でhttps://xamarin.comと同じ動作をすることができません。私は確認してお知らせします。 –

+1

@DiomedesDomínguez、あなたがエミュレータでテストしていたときに、このフォントの問題もありますか? – Jason

+1

はい、私はシミュレータと物理的なスマートフォンの両方で同じ動作をしています。 –

1

それはサイズがiPhoneからの利用しやすさ、設定によって上書きされることは可能ですか?

参照設定 - アプリケーション - >一般 - >アクセス可能性 - >文字の拡大

(自由ドイツ語から翻訳され、実際のメニュー項目が異なる名前を付けることがあります)

1

私は同じ問題に直面しています。

Xamarin.Formsでは、アプリケーションの解像度は起動画面に基づいています。起動画面にアセット(LaunchImage)を使用している場合。次に、LaunchImageごとにアプリの解像度が設定されます。

最高のソリューションは、ストーリーボード(LaunchScreen.storyboard)またはXIBを起動画面に使用することです。これにより、アプリのUIが向上します。フォントサイズとアプリの解像度のような

+0

これは、WebViewを使用してWebサイトを読み込むことには何もありません。 PCLで –

関連する問題