viewDidLoadメソッドでスーパービューに追加したいスクロールビューがあります。私は次のコードでこれを行います:
[self.view addSubview:self.scroll];
NSMutableArray *constraints = [NSMutableArray arrayWithCapacity:4];
[constraints addObject:[NSLayoutConstraint constraintWithItem:self.scroll
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1
constant:0]];
[constraints addObject:[NSLayoutConstraint constraintWithItem:self.scroll
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1
constant:0]];
[constraints addObject:[NSLayoutConstraint constraintWithItem:self.scroll
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1
constant:0]];
[constraints addObject:[NSLayoutConstraint constraintWithItem:self.scroll
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeHeight
multiplier:0.5
constant:0]];
[self.view addConstraints: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)
(""、 ""、 ""、 "")
制約を破って回復しようとします
誰かが私が間違っていることを教えてもらえますか?ありがとうございました。