也就是说
LayoutConstraint 和frame 不共存 frame就不多说了
相对布局主要的就是建立约束条件
- (IBAction)sliderChange:(id)sender
{
//为了避免冲突移除myView的水平和垂直约束,注意是从主视图上移除,因为约束是加载我们的主视图上,即相对于我们的主视图
[self.view removeConstraint:self.widthC];
[self.view removeConstraint:self.heightC];
//获取slider的值
double sliderValue = self.mySlider.value;
//由slider的值重设我们的约束值,H代表水平约束, V代表垂直约束
NSString *widthValue = [NSString stringWithFormat:@"H:[_myView(%lf)]", sliderValue];
NSString *heightValue = [NSString stringWithFormat:@"V:[_myView(%lf)]", sliderValue];
//新建约束
NSArray *widthConstraint = [NSLayoutConstraint constraintsWithVisualFormat:widthValue options:0 metrics:nil views:NSDictionaryOfVariableBindings(_myView)];
//给水平约束重新赋值
self.widthC = widthConstraint[0];
//给垂直约束重新赋值
NSArray * heightConstraint = [NSLayoutConstraint constraintsWithVisualFormat:heightValue options:0 metrics:nil views:NSDictionaryOfVariableBindings(_myView)];
self.heightC = heightConstraint[0];
//往主视图上添加新的约束
[self.view addConstraint:self.widthC];
[self.view addConstraint:self.heightC];
}