-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathViewController.m
More file actions
47 lines (38 loc) · 1.55 KB
/
ViewController.m
File metadata and controls
47 lines (38 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// ViewController.m
// ViewMover
//
// Created by Steven Hepting on 11/12/15.
// Copyright © 2015 Hepting. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *grayView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadingConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *trailingConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
@end
@implementation ViewController
- (IBAction)moveButtonTapped:(id)sender {
[UIView animateWithDuration:0.3 animations:^{
if(self.leadingConstraint.priority == UILayoutPriorityDefaultHigh){
// Move to right
self.leadingConstraint.priority = UILayoutPriorityDefaultLow;
self.trailingConstraint.priority = UILayoutPriorityDefaultHigh;
// Move to bottom
self.topConstraint.priority = UILayoutPriorityDefaultLow;
self.bottomConstraint.priority = UILayoutPriorityDefaultHigh;
}
else{
// move back to left
self.leadingConstraint.priority = UILayoutPriorityDefaultHigh;
self.trailingConstraint.priority = UILayoutPriorityDefaultLow;
// Move back to top
self.topConstraint.priority = UILayoutPriorityDefaultHigh;
self.bottomConstraint.priority = UILayoutPriorityDefaultLow;
}
[self.view layoutIfNeeded];
}];
}
@end