目标是无论我处于纵向还是横向模式,我的图像都将位于距离超级视图的左边缘 20 处,而 viewHolder 也将位于距离超级视图的底部边缘 20 处。
我正在做的是
视图控制器.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;
视图控制器.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 根本不会以纵向或横向显示。图片附在下面
我在这里缺少什么,如果您对此有任何想法,请提供帮助。谢谢