繁体   English   中英

为什么会有突破性的约束?

[英]Why are there breaking constraints?

我试图学习视觉格式语言,并且试图弄清打破自动布局约束的情况。

    /**
 * @Name: setUpContainerViews
 * @Description: This is will set up the different 
 * @Parameters: None
 * @Returns: void
 * @Throws: No Exception
 */

- (void)setUpContainerViews {
    tallContainer = [[UIView alloc] init];
    self.topContainerView = [[UIView alloc] init];
    self.bottomContainerView = [[UIView alloc] init];
    self.leftContainerView = [[UIView alloc] init];
    self.rightContainerView = [[UIView alloc] init];

    // We need to add the subviews here because auto layout needs them to be a part of the view.
    [self.view addSubview: tallContainer];
    [self.view addSubview: self.rightContainerView];

    [tallContainer addSubview: self.topContainerView];
    [tallContainer addSubview: self.leftContainerView];
    [tallContainer addSubview: self.bottomContainerView];

    [self.topContainerView setBackgroundColor: [UIColor blueColor]];
    [self.rightContainerView setBackgroundColor: [UIColor orangeColor]];
    [self.leftContainerView setBackgroundColor: [UIColor greenColor]];
    [self.bottomContainerView setBackgroundColor: [UIColor lightGrayColor]];
}

/**
 * @Name: setUpLayoutConstraints
 * @Description: This will set up the layout constraints
 * @Parameters: none
 * @Returns: void 
 * @Throws: No Exception
 */

- (void)setUpLayoutConstraints {

    // Check if all three properties exist
    NSMutableArray *constraintArray = [NSMutableArray array];

    NSDictionary *views = @{
                                @"tallContainer":tallContainer,
                                @"topContainer":self.topContainerView,
                                @"leftContainer":self.leftContainerView,
                                @"rightContainer":self.rightContainerView,
                                @"bottomContainer":self.bottomContainerView
                           };

    // This is for the self.view
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[tallContainer]-(0)-[rightContainer(50)]-(0)-|" options:0 metrics:nil views: views]];

    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|-(0)-[tallContainer]-(0)-|" options:0 metrics:nil views: views]];
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|-(0)-[rightContainer]-(0)-|" options:0 metrics:nil views: views]];

    // This is for the tall container
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|-(0)-[topContainer(75)]-(0)-[leftContainer]-(0)-[bottomContainer(75)]-(0)-|" options:0 metrics:nil views: views]];

    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[topContainer]-(0)-|" options:0 metrics:nil views: views]];
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[leftContainer]-(0)-|" options:0 metrics:nil views: views]];
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[bottomContainer]-(0)-|" options:0 metrics:nil views: views]];

    // This will add the constraints
    [self.view addConstraints: [constraintArray copy]];
}

这些首先是打破的约束,需要更多...

       2015-05-16 11:08:34.222 HighSchoolUMS[4776:1420732] 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) 
    (
        "<NSLayoutConstraint:0x7fe898e11760 V:|-(0)-[UIView:0x7fe898e0f210]   (Names: '|':UIView:0x7fe898e0f100 )>",
        "<NSLayoutConstraint:0x7fe898e117e0 V:[UIView:0x7fe898e0f210(75)]>",
        "<NSAutoresizingMaskLayoutConstraint:0x7fe898d2bb80 h=--& v=--& UIView:0x7fe898e0f210.midY ==>"
    )

    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0x7fe898e11760 V:|-(0)-[UIView:0x7fe898e0f210]   (Names: '|':UIView:0x7fe898e0f100 )>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
    The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

我不知道他们为什么要打破它,这似乎很简单,我在这里错过了什么吗? (很明显,我是)这个应用程序在横向方向上是有帮助的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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