我正在尝试在viewDidLoad中为iPhone 4S,5,5S更改
ImageView的约束:
@H_301_2@for (NSLayoutConstraint *constraint in logoImage.constraints) {
if ([constraint.identifier isEqualToString:@"logoTopIdentifier"]) {
constraint.constant=10;
}
}
似乎它甚至不在循环中迭代.有没有其他方法来获得具有标识符的特定约束?
解决方法
您可以将storyboard中的约束连接到视图控制器类,与连接UI元素相同.
只需在故事板中找到约束,将工作区设置为拆分视图,然后将约束拖动到相应的视图控制器类.
有时,如果要为位置更改设置动画,可以更新约束,如:
@H_301_2@self.theConstraint?.constant = 100 self.view.setNeedsUpdateConstraints() UIView.animateWithDuration(0.7) { () -> Void in self.view.layoutIfNeeded() }块.
这就对了.