更改显示的视图控制器约束

时间:2018-06-15 15:22:45

标签: c# ios uiviewcontroller constraints

我试图在一段时间内找到答案。我想要做的是改变与他的"父亲"相关的ViewController的约束。 这是我试图做的,但我收到一个错误:

 partial void BackAction(Foundation.NSObject sender)
 {
   /// My "parent" view controller - the one that presented this view
   UIViewController ApplicationViewController = Application.GetPresentedViewController("ApplicationViewController");
   /// Here I am trying to update the constrains in relation with his father  
   View.AddConstraint(NSLayoutConstraint.Create(ApplicationViewController.View, NSLayoutAttribute.LeftMargin, NSLayoutRelation.Equal, 1, 30));
   /// and also let the view digest the constrains
   View.UpdateConstraints();
 }

当我添加约束时,我收到此错误:

Objective-C exception thrown.  
Name: NSInvalidArgumentException 
Reason: NSLayoutConstraint for <UILayoutContainerView: 0x104903e70; frame = (0 0; 375 812); autoresize = W+H; layer = <CALayer: 0x1c802ff20>>: 
A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. 
Location attributes must be specified in pairs.

请帮我看看,谢谢

1 个答案:

答案 0 :(得分:1)

您需要添加缺少的视图参数。

  

Create(NSObject,NSLayoutAttribute,NSLayoutRelation,NSObject,   NSLayoutAttribute,nfloat,nfloat)

View.AddConstraint(NSLayoutConstraint.Create(ApplicationViewController.View, NSLayoutAttribute.LeftMargin, NSLayoutRelation.Equal,View,NSLayoutAttribute.LeftMargin,1, 30));