次の実装に問題があります。
+-------------------+
| |
| |
| RESIZABLE |
| |
| NSVIEW |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|+-----------------+|
|| ||
|| STATIC ||
|| ||
|| SUBVIEW ||
|| ||
|+-----------------+|
+-------------------+
サブビューの縦横比を一定に保つ必要がある場所 (ユーザーがサイズ変更可能なビューの幅を変更するため)。
これまでのところ、制約を使用してそれを行いたいと思います:
//This is a snippet of the resizable view class
[self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:subview attribute:NSLayoutAttributeWidth multiplier:1 constant:0]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:subview attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
//This is a snippet of the subview class
[self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeWidth multiplier:aspectRatio constant:0]];
サイズ変更可能なビューのフレームは、最初に設定されています。この場合、サブビューのフレームを設定しないのは理にかなっていますか? 現時点では、メイン ビューが消えているように見えます。最初は幅 0 です。
どうすればいいですか - 可能であれば、制約を使用したいと思います!