@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *redTop; //绑定约束
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//只是修改约束
self.redTop.constant += 50;
[UIView animateWithDuration:0.5 animations:^{
//调用这个方法,可以刷新View上所有约束
[self.view layoutIfNeeded];
}];
}