在Xamarin.iOS中将标签页移到顶部时,请删除底部的空白区域 [英] Remove white space at the bottom when moving tabs to the top in Xamarin.iOS

查看:99
本文介绍了在Xamarin.iOS中将标签页移到顶部时,请删除底部的空白区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据Youtube的最新UI创建选项卡式菜单,并在Android和iOS上将菜单显示在顶部.

I need to create the tabbed menu as per Youtube's latest UI and show the menu at the top on Android and iOS.

Android上的默认行为是在顶部显示菜单,以便正常工作.

The default behavior on Android is to show menu at the top so that's working fine.

在iOS上,我创建了一个自定义渲染,并使用以下代码将栏的位置更改为顶部:

On iOS I have created a custom render and I am using following code to change the position of the bar to the top:

UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;

if (UIInterfaceOrientation.LandscapeLeft == orientation || UIInterfaceOrientation.LandscapeRight == orientation)
{
    tabSize = 32.0f;
}

CGRect tabFrame = this.TabBar.Frame;

tabFrame.Height = tabSize;

tabFrame.Y = this.View.Frame.Y;

this.TabBar.Frame = tabFrame;
this.TabBar.ContentMode = UIViewContentMode.ScaleToFill;

// Set the translucent property to NO then back to YES to
// force the UITabBar to reblur, otherwise part of the
// new frame will be completely transparent if we rotate
// from a landscape orientation to a portrait orientation.

this.TabBar.Translucent = false;
this.TabBar.Translucent = true;
//this.TabBar.Translucent = false;
this.TabBar.SetNeedsUpdateConstraints();

我的问题是,底部有一些空白以补偿已经移到顶部的条形图.

My problem is that there is some white space at the bottom to compensate for the bar which is already moved to the top.

有人知道如何解决此问题吗?

Does any one knows how to fix this?

此问题也在以下帖子中,但我找不到答案. https://forums.xamarin.com/discussion/comment/226114/#Comment_226114

This problem is also in following post but I am not able to find answer. https://forums.xamarin.com/discussion/comment/226114/#Comment_226114

推荐答案

删除TabbedPageRenderer并创建PageRenderer

Remove the TabbedPageRenderer and Create a PageRenderer

[assembly: ExportRenderer(typeof(ContentPage), typeof(PageiOS))]
namespace TabBarDemo1.iOS.Renderer
{
public class PageiOS : PageRenderer
{
    public override void ViewWillLayoutSubviews()
    {
        base.ViewWillLayoutSubviews();

        nfloat tabSize = 44.0f;

        UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;

        if (UIInterfaceOrientation.LandscapeLeft == orientation || UIInterfaceOrientation.LandscapeRight == orientation)
        {
            tabSize = 32.0f;
        }

        CGRect rect = this.View.Frame;
        rect.Y = this.NavigationController != null ? tabSize : tabSize+20;
        this.View.Frame = rect;

        if(TabBarController != null) {
            CGRect tabFrame = this.TabBarController.TabBar.Frame;
            tabFrame.Height = tabSize;
            tabFrame.Y = this.NavigationController != null?64:20;
            this.TabBarController.TabBar.Frame = tabFrame;
            this.TabBarController.TabBar.BarTintColor = UIColor.Red;
        }
    }
}

}

我的测试

PS:

它在人像"模式下可以完美运行,但需要在其他模式下进行调整,您可以自己完成.

It works perfectly in the Portrait mode, but it needs to adjust in other mode, you can complete it by yourself.

这篇关于在Xamarin.iOS中将标签页移到顶部时,请删除底部的空白区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆