【问题标题】:How do I remove the extra padding when displaying the MasterDetail Master view显示 MasterDetail 主视图时如何删除额外的填充
【发布时间】:2018-01-12 22:27:35
【问题描述】:

在 iPhoneX 上以横向模式打开 Xamarin Forms MasterDetail 窗口的 Master 部分时,似乎没有删除用于容纳安全区域的填充,从而导致汉堡包和主视图之间存在巨大差距。这在 iPhone 8 上不存在。

iPhone X:

iPhone 8:

另外,master area左边的safe area的颜色和detail view的颜色是一样的,怎么让master view的颜色延伸到这个区域呢?

【问题讨论】:

    标签: xamarin.forms iphone-x


    【解决方案1】:

    要扩展颜色,您只需设置页面的背景颜色,对于插图,您可以调整它们。

    public YourPage()
    {
        InitializeComponent();
    
        On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);
        BackgroundColor = Color.YourColor;
    }
    
    protected override void OnAppearing()
    {
        base.OnAppearing();
    
        var inset = On<Xamarin.Forms.PlatformConfiguration.iOS>().SafeAreaInsets();
        inset.Left = 24;
        Padding = inset;
    }
    

    请记住,如果您的应用可以在纵向和横向之间旋转,您可能还需要 override OnSizeAllocated 来处理在那里设置插图。

    【讨论】:

    • 我看不出将 BackgroundColor 设置为单一颜色会如何将颜色从主视图扩展到左侧安全区域,因为它不是一种纯色。
    • 如果你想要所有颜色都穿过你将不得不将 inset 设置为 0 或完全删除 SafeArea 并为视图的内容添加边距,例如看起来像内容的内容您的 ListView 中的 ViewCell ,以便缺口不会覆盖内容。
    猜你喜欢
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 2015-07-06
    • 2017-09-18
    • 1970-01-01
    相关资源
    最近更新 更多