2017-08-17 135 views
0

我需要根據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

回答

1

取出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嗎? –