目標は、ポートレート モードでもランドスケープ モードでも、イメージがスーパー ビューの左端から 20 の位置に配置され、viewHolder もスーパー ビューの下端から 20 の位置に配置されることです。
私がしていることは
ViewController.h
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *verticalConsImage;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) IBOutlet UIView *viewHolder;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConsViewHolder;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topConsViewHolder;
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view removeConstraint:self.verticalConsImage];
[self.view removeConstraint:self.topConsViewHolder];
[self.view removeConstraint:self.bottomConsViewHolder];
//the position of the imageView left edge is equal of the superview’s left edge plus 20.
self.verticalConsImage = [NSLayoutConstraint
constraintWithItem:self.imageView
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeading
multiplier:1.0f
constant:20.0f];
// add it again to the view
[self.view addConstraint:self.verticalConsImage];
//the position of the viewHolder's bottom edge is equal of the superview’s bottom edge plus 20.
self.bottomConsViewHolder = [NSLayoutConstraint
constraintWithItem:self.viewHolder
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:1.0f
constant:20.0f];
// add it again to the view
[self.view addConstraint:self.bottomConsViewHolder];
ただし、アプリを実行すると、viewHolder は縦向きにも横向きにもまったく表示されません。以下に画像を添付します
ここに欠けているもの、これについて何かアイデアがあれば助けてください。ありがとう