2016-10-31 49 views

回答

1

你应该能够乘数设定为1:2,因为它与比的作品。

我觉得这是Visual Studio中的iOS设计器中的一个错误,因为乘数是一个浮点数。来自文档here

乘数:属性2的值乘以该浮点数。在这种情况下,乘数是1.0。

在Xamarin Studio中,iOS的设计的比率被接受,而且1/20.5

enter image description here

而且在Xcode中:

enter image description here

它甚至被添加到源的xib/storyboard如下:

<constraint id="9" firstItem="3" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" multiplier="1:2"/> 

因此,您可以编辑.xib或.storyboard文件,但那不太理想。

来设定倍频的替代,你可以设置:

RedView

  • LeadingSpace到superview.leadingspace

  • TrailingSpace到superview.CenterX

GREENVIEW

  • LeadingSpace到superview.CenterX

  • TrailingSpace到superview.trailingspace

这将做一样的宽度设定到的所述宽度尺寸的一半上海华。

TBH Visual Studio和Xamarin工作室的iOS设计师与Xcode在增加复杂约束方面相比并不是很好(这并不复杂,但仍然失败)。如果可以,我会建议尝试在Xcode中进行编辑。

更新

如果您希望通过编程添加它们,在ViewDidLoad补充一点:

public override void ViewDidLoad() 
{ 
    base.ViewDidLoad(); 

    greenView.TranslatesAutoresizingMaskIntoConstraints = false; 
    redView.TranslatesAutoresizingMaskIntoConstraints = false; 

    View.AddConstraints(new NSLayoutConstraint[]{ 
     NSLayoutConstraint.Create(redView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1, 0), 
     NSLayoutConstraint.Create(redView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1, 0), 
     NSLayoutConstraint.Create(redView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1, 0), 

     NSLayoutConstraint.Create(greenView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, View, NSLayoutAttribute.CenterX, 1, 0), 
     NSLayoutConstraint.Create(greenView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1, 0), 
     NSLayoutConstraint.Create(greenView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, redView, NSLayoutAttribute.Top, 1, 0), 
    }); 
} 

它将使像这样一个观点:

portland

+0

乘数不接受它。只接受整数值。你能否请你解释一下。 –

+0

我更新了一些额外的信息 –

+0

我的答案谢谢你的很好的解释。确实这是Visual Studio iOS Designer中的错误。我仍然有1个问题。我如何将trailingSpace设置为superview.CenterX?没有编辑约束的选项。我应该以编程的方式吗? 顺便说一句,我发现了另一种廉价的解决方案。 –

相关问题