在我的xamarin iOS应用程序中,我有一个列表视图,我想在加载时显示加载图标。但是,我不想禁用整个页面。我希望用户如果愿意,仍然可以使用后退导航返回。iOS:在加载覆盖期间启用导航
我用this作为参考。
所以,我试图设置CGRect框架,将导航保留在最前面,并在加载状态期间禁用页面的其余部分。
我使用的是这样的:new CGRect(30, 0,0, 0)
从顶部留下30个单位,但它不起作用。任何人都可以帮助我有一个框架离开只是导航栏和覆盖页面的其余部分?
在我的xamarin iOS应用程序中,我有一个列表视图,我想在加载时显示加载图标。但是,我不想禁用整个页面。我希望用户如果愿意,仍然可以使用后退导航返回。iOS:在加载覆盖期间启用导航
我用this作为参考。
所以,我试图设置CGRect框架,将导航保留在最前面,并在加载状态期间禁用页面的其余部分。
我使用的是这样的:new CGRect(30, 0,0, 0)
从顶部留下30个单位,但它不起作用。任何人都可以帮助我有一个框架离开只是导航栏和覆盖页面的其余部分?
AutoLayout是比使用框架更好的完成此任务的方法。除非你需要真正针对iOS的老版本,否则AutoLayout通常是最好的选择。
我假设您使用的是UIViewController
而不是UITableViewController
。这是一个重要的区别,因为UITableViewController
只允许您添加到UITableView
,这使得这项任务更具挑战性。
将此AddAnOverlay
方法添加到您的UIViewController
类中,然后在需要显示叠加层时调用它。您可能需要将overlay
放在实例变量中,以便稍后将其删除。致电overlay.RemoveFromSuperview()
将其删除,即可完成。
void AddAnOverlay()
{
var overlay = new UIView();
overlay.BackgroundColor = UIColor.Black.ColorWithAlpha(0.45f); // or whatever colo
overlay.TranslatesAutoresizingMaskIntoConstraints = false;
var label = new UILabel();
label.TranslatesAutoresizingMaskIntoConstraints = false;
label.Text = "Loading Fantastic Things!";
var spinner = new UIActivityIndicatorView();
spinner.TranslatesAutoresizingMaskIntoConstraints = false;
spinner.StartAnimating();
overlay.AddSubview(spinner);
overlay.AddConstraint(NSLayoutConstraint.Create(overlay, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, spinner, NSLayoutAttribute.CenterX, 1, 0));
overlay.AddConstraint(NSLayoutConstraint.Create(overlay, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, spinner, NSLayoutAttribute.CenterY, 1, 0));
overlay.AddSubview(label);
// can adjust space between by changing -30 to whatever
overlay.AddConstraint(NSLayoutConstraint.Create(spinner, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, label, NSLayoutAttribute.Top, 1, -30));
overlay.AddConstraint(NSLayoutConstraint.Create(overlay, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, label, NSLayoutAttribute.CenterX, 1, 0));
View.AddSubview(overlay);
View.AddConstraint(NSLayoutConstraint.Create(TopLayoutGuide, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, overlay, NSLayoutAttribute.Top, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(View, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, overlay, NSLayoutAttribute.CenterX, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(View, NSLayoutAttribute.Width, NSLayoutRelation.Equal, overlay, NSLayoutAttribute.Width, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(BottomLayoutGuide, NSLayoutAttribute.Top, NSLayoutRelation.Equal, overlay, NSLayoutAttribute.Bottom, 1, 0));
}
请注意,在NSLayoutConstraint
的TopLayoutGuide
和BottomLayoutGuide
。这些代表了当前视图控制器的顶部和底部,因此它们可用于调整大小以避免隐藏导航栏,选项卡栏等。
您必须将叠加层添加到表视图,这会将您引向居中问题。为此,有一些选项:在滚动时重新计算叠加层的位置,在您引用自动布局定位的表视图后面添加一个附加图层...
我使用自动布局,并且应该避免给出实际数字,但它也可以使用边界。另外请注意,如果用户导航,你必须取消任务!