将标签移至Xamarin顶部时删除底部的空白空间.iOS

将标签移至Xamarin顶部时删除底部的空白空间.iOS

问题描述:

我需要根据Youtube的最新用户界面创建标签式菜单,并在Android和iOS上显示顶部的菜单。将标签移至Xamarin顶部时删除底部的空白空间.iOS

Android上的默认行为是在顶部显示菜单,因此工作正常。

在iOS上我创建了一个自定义的渲染,我使用下面的代码来改变棒的顶端位置:

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(); 

我的问题是,有在底部一些空白来补偿对于已经移动到顶部的酒吧。

有没有人知道如何解决这个问题?

此问题也在以下文章中,但我无法找到答案。 https://forums.xamarin.com/discussion/comment/226114/#Comment_226114

取出TabbedPageRenderer和创建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; 
     } 
    } 
} 

}

我的测试

enter image description here

PS:

它完美的肖像模式,但需要在其他模式下进行调整,您可以自己完成。

+0

这没关系。但实际上标签栏不会在标题中。请参阅YouTube应用。 在这种情况下,顶部有不必要的空白。 – Hetal

+0

@HetalJariwala我不明白,你能附上图像来描述你面临什么问题吗? –

+0

@HetalJariwala你看到我的测试gif吗? –