0

私はビジュアル フォーマット言語について学習しようとしていますが、自動レイアウトの制約を破る文字列が得られることを理解しようとしています。

    /**
 * @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.

なぜ彼らが壊れているのかわかりません。単純なことのように思えますが、ここで何かが欠けていますか? (明らかに私はそうです)このアプリは横向きで、まったく役に立ちます。

4

0 に答える 0