2017-08-29 57 views
0

与状态栏干扰我已经创建滑动菜单中Xamarin.iOS下面库https://github.com/thedillonb/MonoTouch.SlideoutNavigation的UITableView在Xamarin.iOS

SplashViewController.cs

window = new UIWindow(UIScreen.MainScreen.Bounds); 
Menu = new SlideoutNavigationController(); 

var storyboard = UIStoryboard.FromName("Main", null); 
var webController = storyboard.InstantiateViewController("HomeViewController") as HomeViewController; 

Menu.MainViewController = new MainNavigationController(webController, Menu); 
Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = true }; 

window.RootViewController = Menu; 
window.MakeKeyAndVisible(); 

DummyControllerLeft.cs

public override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 

      TableView.Frame = new RectangleF((float)TableView.Frame.Left, 30, (float)TableView.Frame.Width, (float)(View.Frame.Size.Height - 30)); 
      headerView = new UIView(); 
      headerView.Frame = new CoreGraphics.CGRect(0, 0, TableView.Frame.Width, 140); 

      profileImage = new UIImageView(); 
      profileImage.Frame = new CoreGraphics.CGRect(10, 10, 70, 70); 
      profileImage.Layer.CornerRadius = 35; 
      profileImage.ClipsToBounds = true; 
      profileImage.Image = UIImage.FromBundle("gargi_logo.png"); 

      userName = new UILabel(); 
      userName.Frame = new CoreGraphics.CGRect(10, 90, TableView.Frame.Width - 20, 20); 
      userName.Font = GargiFontAndSize.B14(); 
      userName.TextColor = UIColor.White; 
      headerView.AddSubview(userName); 

      userRole = new UILabel(); 
      userRole.Frame = new CoreGraphics.CGRect(10, 110, TableView.Frame.Width - 20, 20); 
      userRole.Font = GargiFontAndSize.B14(); 
      userRole.TextColor = UIColor.White; 
      headerView.AddSubview(userRole); 

      headerView.AddSubview(profileImage); 
      TableView.TableHeaderView = headerView; 

      TableView.ContentInset = new UIEdgeInsets(20, 0, 0, 0); 

      GetUserItemData(); 

      SetSidePanel(); 

     } 

其工作正常。

画面1:

enter image description here

,但是当我把它的滚动与状态栏干扰见下图。

屏幕2:

enter image description here

我已经尝试了几乎所有的解决方案或替代方法,但没有什么是我帮助。他们中的少数人在下面。

试过1:

TableView.ContentInset = new UIEdgeInsets(20, 0, 0, 0); 

试过2:

TableView.ScrollRectToVisible(new CGRect(0, 0, 1, 1), true); 

试过3:

EdgesForExtendedLayout = UIRectEdge.None; 
    ExtendedLayoutIncludesOpaqueBars = false; 
    AutomaticallyAdjustsScrollViewInsets = false; 

我试图解决这个问题最近6个小时,但没有任何帮助。

任何帮助将被赞赏。

+0

您正在给视图显示绑定呈现的整个屏幕的高度和宽度(window = new UIWindow(UIScreen.MainScreen.Bounds);)您需要为顶部状态栏留出空间。 – Digitalsa1nt

+0

@ Digitalsa1nt等待我添加顶部状态栏高度并检查它。 – Ironman

+0

@ Digitalsa1nt,但它也像NavigationBar和其他东西一样的整体布局。我想保持其他视图控制器与以前相同,但仅在'DummyControllerLeft'中进行更改,它扩展了'DialogViewController'。 – Ironman

回答

0

如果所有的菜单行都在一个单独的部分中,您可以将您的'TableHeaderView'更改为'SectionHeader',该部分在滚动时保持原位,理论上应该可以解决您的问题。

我想你可能需要创建一个源委托类的实现代码如下做到这一点,但因为财产不暴露自身的tableview中,所以你需要做这样的事情:

它分配给你的表视图:

yoursource source = new yoursource(); 
TableView.Source = source; 

创建委托类:

using CoreGraphics; 
using Foundation; 
using System; 
using UIKit; 

namespace somenamespace 
{ 
    class yoursource : UITableViewSource 
    { 
     public ThreadTableSource(UITableView table, List<ConversationThread> Threads) 
     { 

     } 

     public override UIView GetViewForHeader(UITableView tableView, nint section) 
     { 
      headerView = new UIView(); 
      headerView.Frame = new CoreGraphics.CGRect(0, 0, tableView.Frame.Width, 140); 

      profileImage = new UIImageView(); 
      profileImage.Frame = new CoreGraphics.CGRect(10, 10, 70, 70); 
      profileImage.Layer.CornerRadius = 35; 
      profileImage.ClipsToBounds = true; 
      profileImage.Image = UIImage.FromBundle("gargi_logo.png"); 

      userName = new UILabel(); 
      userName.Frame = new CoreGraphics.CGRect(10, 90, tableView.Frame.Width - 20, 20); 
      userName.Font = GargiFontAndSize.B14(); 
      userName.TextColor = UIColor.White; 
      headerView.AddSubview(userName); 

      userRole = new UILabel(); 
      userRole.Frame = new CoreGraphics.CGRect(10, 110, tableView.Frame.Width - 20, 20); 
      userRole.Font = GargiFontAndSize.B14(); 
      userRole.TextColor = UIColor.White; 
      headerView.AddSubview(userRole); 

      headerView.AddSubview(profileImage); 

      return headerView; 
     } 
    } 
} 

Link to section header xamarin guide.