我需要根据Youtube的最新用户界面创建标签式菜单,并在Android和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
答案 0 :(得分: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;
}
}
}
}
我的测试
PS:
它在人像模式下完美运行,但需要在其他模式下调整,您可以自己完成。