나는 UIImageView
가로 및 세로로 가운데 self.view
에 고정 된 수평 간격을두고 수평으로 배치 하고 싶은 세 개의 s (서로 옆에 배치)가 있습니다. 나는 레이아웃 제약을 사용하는 것에 대해 잘 이해하지 못하고, 그것들을 중간 컨테이너에 배치하고 autoresizingMask
적절하게 설정 하면 트릭을 할 수 있다는 것을 알고 있습니다 .
containerView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
중간 컨테이너를 사용하지 않고 동일한 효과를 얻으려면 무엇이 필요할까요?
당신은 이미지 전망이 가정 leftImageView
, rightImageView
그리고 centerImageView
보기에, 이러한 제약을 트릭을 수행해야합니다
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerImageView
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:centerImageView
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1
constant:0]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[leftImage]-[centerImage]-[rightImage]"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:@{@"leftImage" : leftImageView,
@"rightImage" : rightImageView,
@"centerImage" : centerImageView}]];
translatesAutoresizingMaskIntoConstraints
각 이미지보기에서 거짓 인지 확인하십시오 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다