UITableView在Xamarin.iOS中干扰状态栏

时间:2017-08-29 13:03:02

标签: ios uitableview xamarin xamarin.ios dialogviewcontroller

我在Xamarin.iOS中使用以下库https://github.com/thedillonb/MonoTouch.SlideoutNavigation

创建了幻灯片菜单

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个小时内解决了这个问题,但对我来说没有任何帮助。

任何帮助都会得到赞赏。

1 个答案:

答案 0 :(得分:0)

如果您的所有菜单“行”都在一个部分中,您可以将“TableHeaderView”更改为“SectionHeader”,该部分会在部分滚动时保留,并且理论上应解决您的问题。

我认为您可能需要为tableview创建一个源委托类来执行此操作,因为该属性不会自动暴露给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.