英文:
Xamarin flymenu cover iPhone status bar
问题
Code run at iPhone7 screenshot:
Same Code run at iPhone8 screenshot -> flymenu cover status bar:
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上运行的截图:
在iPhone8上运行的截图 -> 状态栏遮挡了flymenu:
英文:
Code run at iPhone7 screenshot
Same Code run at iPhone8 sreenshot -> flymenu cover status bar
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; }
}
}
above code run at iPhone7 screenshot
run at iPhone8 screenshot ->status bar cover flymenu
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
.
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论