2017-08-29 28 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.