简体   繁体   中英

Changing Presented view controller constraints

I have tried to find an answer to this for a while. What I want to do is to change the constraints of a ViewController in relation with his "father". Here is what I tried to do, but I get an error:

 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();
 }

When I am adding the constraints, I get this error:

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.

Please help me find out, thanks

You need to add the missing view parameter.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM