Empêcher Interface Builder de créer automatiquement des contraintes?

J'ai créé un projet de démonstration ici . J'ai une vue où j'ai créé un ScrollView dans un file .xib. Dans le constructor d'interface, je n'ai défini aucune contrainte. Dans ma méthode viewDidLoad, j'ai défini des contraintes avec SnapKit :

scrollView.snp_makeConstraints { (make) -> Void in make.edges.equalTo(self.view) } 

Quand je cours le code j'obtiens la sortie de console suivante:

 Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSIBPrototypingLayoutConstraint:0x7b74e280 'IB auto generated at build time for view with fixed frame' V:|-(1)-[UIScrollView:0x7b74c430] (Names: '|':UIView:0x7b74dd10 )>", "<<DeviceImagesTest.LayoutConstraint:0x7baa2760> <UIScrollView:0x7b6608d0>.top == <UIView:0x7b64d800>.top>" ) Will attempt to recover by breaking constraint <NSIBPrototypingLayoutConstraint:0x7b74e280 'IB auto generated at build time for view with fixed frame' V:|-(1)-[UIScrollView:0x7b74c430] (Names: '|':UIView:0x7b74dd10 )> Break on objc_exception_throw to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listd in <UIKit/UIView.h> may also be helpful. 2015-05-29 18:37:14.368 DeviceImagesTest[36462:607] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSIBPrototypingLayoutConstraint:0x7b74e080 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIScrollView:0x7b74c430](LTR) (Names: '|':UIView:0x7b74dd10 )>", "<NSIBPrototypingLayoutConstraint:0x7b74e330 'IB auto generated at build time for view with fixed frame' H:[UIScrollView:0x7b74c430(600)]>", "<<DeviceImagesTest.LayoutConstraint:0x7baa7170> <UIScrollView:0x7baa7b30>.right == <UIView:0x7baa79a0>.right>", "<NSAutoresizingMaskLayoutConstraint:0x7baa4800 h=-&- v=-&- UIView:0x7b74dd10.width == UIViewControllerWrapperView:0x7ba9f060.width>", "<NSAutoresizingMaskLayoutConstraint:0x7baa5180 h=-&- v=-&- UIViewControllerWrapperView:0x7ba9f060.width == UINavigationTransitionView:0x7bc769b0.width>", "<NSAutoresizingMaskLayoutConstraint:0x7baa58e0 h=-&- v=-&- UINavigationTransitionView:0x7bc769b0.width == UILayoutContainerView:0x7bc75140.width>", "<NSAutoresizingMaskLayoutConstraint:0x7baa61a0 h=-&- v=-&- UILayoutContainerView:0x7bc75140.width == UIWindow:0x7bc71870.width>", "<NSAutoresizingMaskLayoutConstraint:0x7baa69a0 h=--- v=--- H:[UIWindow:0x7bc71870(320)]>" ) Will attempt to recover by breaking constraint <<DeviceImagesTest.LayoutConstraint:0x7baa95b0> <UIScrollView:0x7baa9610>.right == <UIView:0x7baa96b0>.right> Break on objc_exception_throw to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listd in <UIKit/UIView.h> may also be helpful. 2015-05-29 18:37:14.496 DeviceImagesTest[36462:607] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSIBPrototypingLayoutConstraint:0x7b74e360 'IB auto generated at build time for view with fixed frame' V:[UIScrollView:0x7b74c430(600)]>", "<<DeviceImagesTest.LayoutConstraint:0x7bc77e40> <UIScrollView:0x7bc7f6a0>.top == <UIView:0x7bc52180>.top>", "<<DeviceImagesTest.LayoutConstraint:0x7bc49420> <UIScrollView:0x7bc74b00>.bottom == <UIView:0x7bc7b970>.bottom>", "<NSAutoresizingMaskLayoutConstraint:0x7baa4960 h=-&- v=-&- UIView:0x7b74dd10.height == UIViewControllerWrapperView:0x7ba9f060.height>", "<NSAutoresizingMaskLayoutConstraint:0x7baa51e0 h=-&- v=-&- UIViewControllerWrapperView:0x7ba9f060.height == UINavigationTransitionView:0x7bc769b0.height>", "<NSAutoresizingMaskLayoutConstraint:0x7baa5940 h=-&- v=-&- UINavigationTransitionView:0x7bc769b0.height == UILayoutContainerView:0x7bc75140.height>", "<NSAutoresizingMaskLayoutConstraint:0x7baa6200 h=-&- v=-&- UILayoutContainerView:0x7bc75140.height == UIWindow:0x7bc71870.height>", "<NSAutoresizingMaskLayoutConstraint:0x7baa69d0 h=--- v=--- V:[UIWindow:0x7bc71870(568)]>" ) Will attempt to recover by breaking constraint <<DeviceImagesTest.LayoutConstraint:0x7bc84790> <UIScrollView:0x7bc848b0>.bottom == <UIView:0x7bc84860>.bottom> Break on objc_exception_throw to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listd in <UIKit/UIView.h> may also be helpful. 

Il semble qu'Interface Builder génère des contraintes pour moi même si je n'en ai pas défini. Cela conduit à un conflit avec mes contraintes que j'ai définies dans le code. Je définis également setTranslatesAutoresizingMasks(false) .

Comment puis-je empêcher Interface Builder de générer automatiquement des contraintes?

Si vous êtes confus au sujet de NSAutoresizingMaskLayoutConstraints dans cette list, cela peut être dû au fait que vous n'avez pas appelé setTranslatesAutoresizingMasksIntoContraints(false) sur cette vue. (bien que j'avais l'printing que SnapKit fait ça pour vous).

Si vous êtes confus au sujet de NSIBPrototypingLayoutConstraint , il s'agit d'une contrainte générée automatiquement par Interface Builder. Pour s'en débarrasser, ajoutez des contraintes Top, Bottom, Leading et Trailing dans Interface Builder et définissez-les à supprimer lors de la génération. Pour plus de détails à ce sujet, consultez http://travisjeffery.com/b/2013/11/preventing-ib-auto-generated-at-build-time-for-view-with-fixed-frame/

UPDATE: url a été changé pour http://travisjeffery.com/b/2013/11/preventing-ib-auto-generated-at-build-time-for-view-with-fixed-frame-when-using-auto- disposition/

Comment puis-je empêcher Interface Builder de générer automatiquement des contraintes?

Façon la plus simple: select la plume ou le story-board dans le browser de projet, allez dans l'inspecteur de files, et décochez "Utiliser la layout automatique".