问题
I need to create the tabbed menu as per Youtube's latest UI and show the menu at the top on Android and iOS.
The default behavior on Android is to show menu at the top so that's working fine.
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?
This problem is also in following post but I am not able to find answer. https://forums.xamarin.com/discussion/comment/226114/#Comment_226114
回答1:
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;
}
}
}
}
My test
PS:
It works perfectly in the Portrait mode, but it needs to adjust in other mode, you can complete it by yourself.
来源:https://stackoverflow.com/questions/45741361/remove-white-space-at-the-bottom-when-moving-tabs-to-the-top-in-xamarin-ios