我有一個UIImageView,我需要在改變方向和屏幕尺寸時擴展(高度和寬度)。我正在使用自動佈局約束。展開自動佈局中改變方向和屏幕尺寸的意見
topImageView.contentMode = UIViewContentModeScaleAspectFit;
topImageView.backgroundColor = [UIColor clearColor];
topImageView.layer.cornerRadius = 5.0f;
topImageView.clipsToBounds = YES;
topImageView.translatesAutoresizingMaskIntoConstraints = NO;
if(login_DO.logoPath)
[topImageView loadImage:login_DO.logoPath];
[self.view addSubview:topImageView];
NSArray *horizontalConstraints =
[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"H:|-(%i)-[topImageView(%f)]",X_OFFSET,VIEW_FRAME_WIDTH-X_OFFSET*2]
options:0 metrics:nil views:@{@"topImageView": topImageView}];
NSArray *verticalConstraints =
[NSLayoutConstraint constraintsWithVisualFormat:[NSString stringWithFormat:@"V:|-(%f)-[topImageView(80)]",navHeight]
options:0 metrics:nil views:@{@"topImageView": topImageView}];
[self.view addConstraints:horizontalConstraints];
[self.view addConstraints:verticalConstraints];
NSLayoutConstraint *leadingMarginForImageConstraint = [NSLayoutConstraint
constraintWithItem:topImageView attribute:NSLayoutAttributeLeadingMargin
relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self.view attribute:
NSLayoutAttributeLeadingMargin multiplier:1.0 constant:X_OFFSET];
NSLayoutConstraint *topMarginForImageConstraint = [NSLayoutConstraint
constraintWithItem:topImageView attribute:NSLayoutAttributeTopMargin
relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self.view attribute:
NSLayoutAttributeTopMargin multiplier:1.0 constant:VIEW_FRAME_WIDTH-X_OFFSET*2];
[self.view addConstraints:@[ leadingMarginForImageConstraint,
topMarginForImageConstraint]];
但圖像沒有擴大。我是新來的自動佈局。我是否缺少任何約束?
任何意見或答案? – Nitish 2014-10-01 09:54:25
您的約束無效_______________ 假設x = 10;寬度= 300; _______________ left = -x;寬度> = -300。 _______________ 與高度相同,就像您在寬度和高度上翻轉圖像一樣。 _______________ 解釋更多你想要實現..會相應地添加一個答案。 – 2014-10-04 13:21:34
添加一個屏幕短.. ..如果可能解釋。 – 2014-10-04 13:29:26