Xamarin 飞行菜单遮盖 iPhone 状态栏。

huangapple go评论58阅读模式
英文:

Xamarin flymenu cover iPhone status bar

问题

Code run at iPhone7 screenshot:
Xamarin 飞行菜单遮盖 iPhone 状态栏。

Same Code run at iPhone8 screenshot -> flymenu cover status bar:
Xamarin 飞行菜单遮盖 iPhone 状态栏。

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<FlyoutPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:FlyOutPageDemo"
             xmlns:localC="clr-namespace:FlyOutPageDemo.PageCollect"
             x:Class="FlyOutPageDemo.MainPage">
    <FlyoutPage.Flyout>
        <local:flyOutMenuPage x:Name="flyMenu"/>
    </FlyoutPage.Flyout>
    <FlyoutPage.Detail>
        <NavigationPage>
            <x:Arguments>
                <localC:Home/>
            </x:Arguments>
        </NavigationPage>
    </FlyoutPage.Detail>
</FlyoutPage>

MainPage.xaml.cs:

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

namespace FlyOutPageDemo
{
    public partial class MainPage : FlyoutPage
    {
        public MainPage()
        {
            InitializeComponent();
            flyMenu.listView.ItemSelected += ListView_ItemSelected;
        }

        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var item = e.SelectedItem as FlyOutItemPage;
            if (item != null)
            {
                Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetPage));
                flyMenu.listView.SelectedItem = null;
                IsPresented = false;   
            }
        }
    }
}

flyOutMenuPage.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:FlyOutPageDemo"
             xmlns:localCol="clr-namespace:FlyOutPageDemo.PageCollect"
             x:Class="FlyOutPageDemo.flyOutMenuPage"
             Title="Fly out Menu">
    <ContentPage.Content>
        <StackLayout>
            <ListView x:Name="listView" x:FieldModifier="public">
                <ListView.ItemsSource>
                    <x:Array Type="{x:Type local:FlyOutItemPage}">
                        <local:FlyOutItemPage Title="Home" IconSource="home.png" TargetPage="{x:Type localCol:Home}"/>
                        <local:FlyOutItemPage Title="Course" IconSource="course.png" TargetPage="{x:Type localCol:Course}"/>
                        <local:FlyOutItemPage Title="About" IconSource="about.png" TargetPage="{x:Type localCol:About}"/>
                        <local:FlyOutItemPage Title="Logout" IconSource="logout.png" TargetPage="{x:Type localCol:LogOut}"/>
                    </x:Array>
                </ListView.ItemsSource>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="33"/>
                                    <ColumnDefinition Width="50"/>
                                </Grid.ColumnDefinitions>
                                <Image Source="{Binding IconSource}"/>
                                <Label Grid.Column="1" Text="{Binding Title}"/>
                            </Grid>                            
                        </ViewCell>                        
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

flyOutMenuPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace FlyOutPageDemo
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class flyOutMenuPage : ContentPage
    {
        public flyOutMenuPage()
        {
            InitializeComponent();
        }
    }
}

FlyOutItemPage.cs:

using System;
using System.Collections.Generic;
using System.Text;

namespace FlyOutPageDemo
{
    class FlyOutItemPage
    {
        public string Title { get; set; }
        public string IconSource { get; set; } 
        public Type TargetPage { get; set; } 
    }
}

上述代码在iPhone7上运行的截图:
Xamarin 飞行菜单遮盖 iPhone 状态栏。

在iPhone8上运行的截图 -> 状态栏遮挡了flymenu:
Xamarin 飞行菜单遮盖 iPhone 状态栏。

英文:

Code run at iPhone7 screenshot
Xamarin 飞行菜单遮盖 iPhone 状态栏。

Same Code run at iPhone8 sreenshot -> flymenu cover status bar
Xamarin 飞行菜单遮盖 iPhone 状态栏。

MainPage.xaml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;FlyoutPage xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
            xmlns:local=&quot;clr-namespace:FlyOutPageDemo&quot;
            xmlns:localC=&quot;clr-namespace:FlyOutPageDemo.PageCollect&quot;
             x:Class=&quot;FlyOutPageDemo.MainPage&quot;&gt;
    &lt;FlyoutPage.Flyout&gt;
        &lt;local:flyOutMenuPage x:Name=&quot;flyMenu&quot;/&gt;
    &lt;/FlyoutPage.Flyout&gt;
    &lt;FlyoutPage.Detail&gt;
        &lt;NavigationPage&gt;
            &lt;x:Arguments&gt;
                &lt;localC:Home/&gt;
            &lt;/x:Arguments&gt;
        &lt;/NavigationPage&gt;
    &lt;/FlyoutPage.Detail&gt;
&lt;/FlyoutPage&gt;

MainPage.xaml.cs

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

namespace FlyOutPageDemo
{
    public partial class MainPage : FlyoutPage
    {
        public MainPage()
        {
            InitializeComponent();
            flyMenu.listView.ItemSelected += ListView_ItemSelected;
        }

        private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var item=e.SelectedItem as FlyOutItemPage;
            if (item!=null)
            {
                Detail=new NavigationPage((Page)Activator.CreateInstance(item.TargetPage));
                flyMenu.listView.SelectedItem = null;
                IsPresented=false;   
            }
        }
    }
}

flyOutMenuPage.xaml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;ContentPage xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
             xmlns:local=&quot;clr-namespace:FlyOutPageDemo&quot;
             xmlns:localCol=&quot;clr-namespace:FlyOutPageDemo.PageCollect&quot;
             x:Class=&quot;FlyOutPageDemo.flyOutMenuPage&quot;
             Title=&quot;Fly out Menu&quot;&gt;
    &lt;ContentPage.Content&gt;
        &lt;StackLayout&gt;
            &lt;ListView x:Name=&quot;listView&quot; x:FieldModifier=&quot;public&quot;&gt;
                &lt;ListView.ItemsSource&gt;
                    &lt;x:Array Type=&quot;{x:Type local:FlyOutItemPage}&quot;&gt;
                        &lt;local:FlyOutItemPage Title=&quot;Home&quot; IconSource=&quot;home.png&quot; TargetPage=&quot;{x:Type localCol:Home}&quot;/&gt;
                        &lt;local:FlyOutItemPage Title=&quot;Course&quot; IconSource=&quot;course.png&quot; TargetPage=&quot;{x:Type localCol:Course}&quot;/&gt;
                        &lt;local:FlyOutItemPage Title=&quot;About&quot; IconSource=&quot;about.png&quot; TargetPage=&quot;{x:Type localCol:About}&quot;/&gt;
                        &lt;local:FlyOutItemPage Title=&quot;Logout&quot; IconSource=&quot;logout.png&quot; TargetPage=&quot;{x:Type localCol:LogOut}&quot;/&gt;
                    &lt;/x:Array&gt;
                &lt;/ListView.ItemsSource&gt;
                &lt;ListView.ItemTemplate&gt;
                    &lt;DataTemplate&gt;
                        &lt;ViewCell&gt;
                            &lt;Grid&gt;
                                &lt;Grid.ColumnDefinitions&gt;
                                    &lt;ColumnDefinition Width=&quot;33&quot;/&gt;
                                    &lt;ColumnDefinition Width=&quot;50&quot;/&gt;
                                &lt;/Grid.ColumnDefinitions&gt;
                                &lt;Image Source=&quot;{Binding IconSource}&quot;/&gt;
                                &lt;Label Grid.Column=&quot;1&quot; Text=&quot;{Binding Title}&quot;/&gt;
                            &lt;/Grid&gt;                            
                        &lt;/ViewCell&gt;                        
                    &lt;/DataTemplate&gt;
                &lt;/ListView.ItemTemplate&gt;
            &lt;/ListView&gt;
        &lt;/StackLayout&gt;
    &lt;/ContentPage.Content&gt;
&lt;/ContentPage&gt;

flyOutMenuPage.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace FlyOutPageDemo
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class flyOutMenuPage : ContentPage
    {
        public flyOutMenuPage()
        {
            InitializeComponent();
        }
    }
}

FlyOutItemPage.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace FlyOutPageDemo
{
    class FlyOutItemPage
    {
        public string Title { get; set; }
        public string IconSource { get; set; } 
        public Type TargetPage { get; set; } 
    }
}

above code run at iPhone7 screenshot
Xamarin 飞行菜单遮盖 iPhone 状态栏。
run at iPhone8 screenshot ->status bar cover flymenu
Xamarin 飞行菜单遮盖 iPhone 状态栏。

Question: How to avoid Flymenu cover status bar ?

答案1

得分: 0

You can manually hide the status bar which will help avoid Flymenu cover it.

在你的 Xamarin iOS 应用程序中,编辑并添加以下键值对到 Info.plist 文件中:

<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
英文:

You can manually hide the status bar which will help avoid Flymenu cover it.

In your Xamarin iOS Application, edit and add following key-value pairs to the Info.plist.

&lt;key&gt;UIStatusBarHidden&lt;/key&gt;  
&lt;true/&gt;  
&lt;key&gt;UIViewControllerBasedStatusBarAppearance&lt;/key&gt;  
&lt;false/&gt;  

huangapple
  • 本文由 发表于 2023年6月6日 11:11:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76411217.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定