在这里和 github 上交叉发布,https://github.com/Clancey/FlyoutNavigation/issues/29。
我有一个奇怪的行为,我试图追踪,我不确定它是 FlyoutNavigation 还是我正在做的其他事情。也许有人可以快速浏览一下,谁比我更了解事物。
示例项目 - https://github.com/benhysell/FlyoutNavigationWithNSLayoutConstraintsError
目标 - 使用https://gist.github.com/praeclarum/5175100,NSLayoutConstraints的 AC# 语法,在这篇博文中描述, http ://praeclarum.org/post/45690317491/easy-layout-a-dsl-for -nslayoutconstraint,带有 FlyoutNavigation。
问题 - 在第一次使用包含 NSLayoutConstraints 的视图时,视图不尊重约束或背景颜色,两者都很奇怪。在随后从 FlyoutNavigation 菜单中“选择”视图时,视图将正确绘制。
设置 - 针对 iPhone 模拟器 6.1 和最新发布的 Xcode 在 Xamarin Beta 通道中工作。
重现步骤 1. 最简单的展示方式是打开 FlytoutNavigation 附带的示例项目并使用以下步骤修改此项目。我在这篇文章中包含了一个指向我修改以显示错误的示例项目的链接。
将要点https://gist.github.com/praeclarum/5175100添加到一个新类中,称之为布局。
将新的 UIViewController 和以下内容添加到 ViewDidLoad(),注意这是从可以在 VS2012 中创建的 Xamarin 'Hello World' 示例应用程序中修改的
public override void ViewDidLoad()
{
base.ViewDidLoad();
View.Frame = UIScreen.MainScreen.Bounds;
View.BackgroundColor = UIColor.Red;
button = UIButton.FromType(UIButtonType.RoundedRect);
button.SetTitle("Click me", UIControlState.Normal);
button.TouchUpInside += (object sender, EventArgs e) =>
{
button.SetTitle(String.Format("clicked {0} times", numClicks++), UIControlState.Normal);
};
View.AddSubview(button);
const int ButtonWidth = 75;
const int HPadding = 22;
const int VPadding = 44;
View.ConstrainLayout(() =>
button.Frame.Width == ButtonWidth &&
button.Frame.Left == View.Frame.Left + HPadding &&
button.Frame.Top == View.Frame.Top + VPadding);
}
在 MainController.cs 中替换
navigation.ViewControllers = Array.ConvertAll (Tasks, title =>
new UINavigationController (new TaskPageController (navigation, title))
);
和
navigation.ViewControllers = Array.ConvertAll(Tasks, title =>
new UINavigationController(new MyViewController(navigation))
);
我的意思是“让每个视图都成为实现 NSLayoutConstraints 的视图”。
运行应用程序,第一个视图返回:
从 FlyoutNavigation 菜单中选择相同的项目,然后它将正确绘制。
我已经通过 FlyoutNavigationController.cs 跟踪了几次,它出现在第二次从 FlyoutNavigation 中选择项目时,第 238 行:
this.View.AddSubview (mainView);
ViewControllers[0].ChildViewControllers[0].View.Frame {{X=160,Y=208,Width=0,Height=0}} System.Drawing.RectangleF
这是视图的错误大小,但是在我越过第 238 行之后:
ViewControllers[0].ChildViewControllers[0].View.Frame {{X=0,Y=0,Width=320,Height=416}} System.Drawing.RectangleF
位置固定,视图将正确绘制。
摘要 - 我已经尝试在单页窗口应用程序中单独使用带有 NSLayoutConstraints 的要点,没有问题,我在想,因为它最终在第二次调用 FlyoutNavigation 后正确绘制我在想有一个“东西”我缺少 FlyoutNavigation,或者设置不正确,我无法将手指放在上面。