diff --git a/ViewMover/Base.lproj/Main.storyboard b/ViewMover/Base.lproj/Main.storyboard index a0b9073..b41682a 100644 --- a/ViewMover/Base.lproj/Main.storyboard +++ b/ViewMover/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -20,7 +20,6 @@ - @@ -29,29 +28,21 @@ - - - + + - - + + - - - - - - diff --git a/ViewMover/ViewController.m b/ViewMover/ViewController.m index 268c762..7803b13 100644 --- a/ViewMover/ViewController.m +++ b/ViewMover/ViewController.m @@ -22,15 +22,24 @@ @implementation ViewController - (IBAction)moveButtonTapped:(id)sender { [UIView animateWithDuration:0.3 animations:^{ - // Move to right - self.leadingConstraint.active = false; - self.trailingConstraint.active = true; - - // Move to bottom - self.topConstraint.active = false; - self.bottomConstraint.active = true; - - [self.view setNeedsLayout]; + 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]; }]; }