首页 > 解决方案 > Xamarin 窗体 iOS 标题栏图标在横向打开时无法正确居中位置转为纵向

问题描述

我有一个在 Android 上不会发生的特定于 iOS 的问题。

如果应用程序中的页面以横向模式打开

在此处输入图像描述

然后转向标题栏中心的徽标肖像,而不是移动到中心离开页面,如下所示:

在此处输入图像描述

如果它以纵向打开然后变成横向,则它不会移动到中心或离开屏幕,而是向左移动,卡在全宽的四分之一左右。

xml:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="PhotoApp.MobileApp.Views.PhotoGaleryPage">
<ContentPage.Resources>
    <ResourceDictionary>
        <Color x:Key="Accent">#96d1ff</Color>
    </ResourceDictionary>
</ContentPage.Resources>
<Shell.TitleView>
    <Image
           HorizontalOptions="Center"
           VerticalOptions="Center" 
        Source="logo.png"  />
</Shell.TitleView>

标签: iosxamlxamarin.formsxamarin.iostitlebar

解决方案


我建议你使用这个:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="PhotoApp.MobileApp.Views.PhotoGaleryPage">
    <ContentPage.Resources>
        <ResourceDictionary>
            <Color x:Key="Accent">#96d1ff</Color>
        </ResourceDictionary>
    </ContentPage.Resources>
    <Shell.TitleView>
  <StackLayout HorizontalOptions="Center"
            Margin="{OnPlatform iOS='0,0,25,0', Android='0,0,20,0', Default=0}"
            Orientation="Horizontal">
        <Image       
            Source="logo.png"  />
   </StackLayout>
    </Shell.TitleView>

推荐阅读