ios视图在导航到其他屏幕后消失
我在故事板上有一个自定义视图,它充当工具栏。这个视图有三个按钮,我为ViewDidLoad中的每个按钮定义了自定义视图 当我导航到另一个视图,然后向后移动到此原始屏幕时,这些按钮上的文本和图像都会丢失。只有一个空的黑酒吧。某些设备会出现这种情况,但视图显示得很好,在其他设备上永远不会消失 我所尝试的:ios视图在导航到其他屏幕后消失,ios,xamarin.ios,Ios,Xamarin.ios,我在故事板上有一个自定义视图,它充当工具栏。这个视图有三个按钮,我为ViewDidLoad中的每个按钮定义了自定义视图 当我导航到另一个视图,然后向后移动到此原始屏幕时,这些按钮上的文本和图像都会丢失。只有一个空的黑酒吧。某些设备会出现这种情况,但视图显示得很好,在其他设备上永远不会消失 我所尝试的: 我已在ViewWillDisplay中将这些按钮的隐藏属性显式设置为false btn1.Hidden=false; btn2.Hidden=false; btn3.Hidden=false 我
- 我已在ViewWillDisplay中将这些按钮的隐藏属性显式设置为false btn1.Hidden=false; btn2.Hidden=false; btn3.Hidden=false
- 我还尝试在ViewWillDisplay而不是ViewDidLoad中定义按钮,看看这是否解决了问题。它们仍然消失
public override void ViewWillAppear(bool value)
{
try
{
base.ViewWillAppear(value);
//icon setup
//the space between the image and modelFilterText
var spacing = 0.3f;
var icon1 = UIImage.FromBundle("Icons/Home/icon1.png");
btn1.SetImage(icon1, UIControlState.Normal);
btn1.SetTitle("ONE", UIControlState.Normal);
btn1.SetTitleColor(UIColor.LightGray, UIControlState.Normal);
btn1.Font = UIFont.FromName("BankGothicBT-Light", 12f);
btnRequest.TouchUpInside += (object sender, EventArgs e) =>
{
NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
NavigationController.PushViewController(view1, true);
};
// lower the modelFilterText and push it left so it appears centered
// below the image
var imageSize = btn1.ImageView.Image.Size;
btn1.TitleEdgeInsets = new UIEdgeInsets(0.0f, -imageSize.Width, -(imageSize.Height + spacing),
0.0f);
// raise the image and push it right so it appears centered
// above the modelFilterText
var titleSize = btn1.TitleLabel.Text.StringSize(btn1.TitleLabel.Font);
btn1.ImageEdgeInsets = new UIEdgeInsets(-(titleSize.Height + spacing), 0.0f, 0.0f,
-titleSize.Width);
//Second Icon
var icon2 = UIImage.FromBundle("Icons/Home/icon2.png");
btn2.SetImage(icon2, UIControlState.Normal);
btn2.SetTitle("TWO", UIControlState.Normal);
btn2.SetTitleColor(UIColor.LightGray, UIControlState.Normal);
btn2.Font = UIFont.FromName("BankGothicBT-Light", 12f);
btn2.TouchUpInside +=
(object sender, EventArgs e) =>
{
NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
};
// lower the modelFilterText and push it left so it appears centered
// below the image
var imgSize = btn2.ImageView.Image.Size;
btn2.TitleEdgeInsets = new UIEdgeInsets(0.0f, -imgSize.Width, -(imgSize.Height + spacing), 0.0f);
// raise the image and push it right so it appears centered
// above the modelFilterText
var titleLength = btn2.TitleLabel.Text.StringSize(btn2.TitleLabel.Font);
btn2.ImageEdgeInsets = new UIEdgeInsets(-(titleLength.Height + spacing), 0.0f, 0.0f,
-titleLength.Width);
//Third Icon
var icon3 = UIImage.FromBundle("Icons/Home/icon3.png");
btn3.SetImage(icon3, UIControlState.Normal);
btn3.SetTitle("THREE", UIControlState.Normal);
btn3.SetTitleColor(UIColor.LightGray, UIControlState.Normal);
btn3.Font = UIFont.FromName("BankGothicBT-Light", 12f);
btn3.TouchUpInside += (object sender, EventArgs e) =>
{
NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
NavigationController.PushViewController(view3, true);
};
// lower the modelFilterText and push it left so it appears centered below the image
var imagSize3 = btn3.ImageView.Image.Size;
btn3.TitleEdgeInsets = new UIEdgeInsets(0.0f, -imagSize3.Width, -(imagSize3.Height + spacing),
0.0f);
// raise the image and push it right so it appears centered
// above the modelFilterText
var titleLength3 = btn3.TitleLabel.Text.StringSize(btn3.TitleLabel.Font);
btn3.ImageEdgeInsets = new UIEdgeInsets(-(titleLength3.Height + spacing), 0.0f, 0.0f,
-titleLength3.Width);
}
catch (Exception ex)
{
Console.WriteLine("View will appear error " + ex.Message + ex.StackTrace);
}
}
按钮第一次出现并正确绘制。然而,当我离开这个页面并返回到它时,在底部只有一个黑色的视图。没有按钮。我知道按钮实际上不会消失。它们被iOS工具栏遮住了 例如,如果我导航到具有iOS工具栏的屏幕,然后向后导航到此主页,则此后所有其他屏幕的
NavigationController.SetToolbarHidden
属性都设置为true
所以我所需要做的就是在这个主页的viewwillbeen中将这个设置为false,这样它就不会模糊我的自定义视图
NavigationController.SetToolbarHidden(true,false)