From 79330cd3cb2e6b474ce13f14be346e817a776239 Mon Sep 17 00:00:00 2001 From: Malcolm Hall Date: Mon, 11 Jan 2016 16:41:01 +0000 Subject: [PATCH] Now moves forward and back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed to use priorities instead of active. This allows the view to be moved back to where it was an allows better visualisation of constraints in Xcode because the lower priority ones have dotted lines and also appear in the views constraint inspector, the uninstalled ones didn’t. --- ViewMover/Base.lproj/Main.storyboard | 21 ++++++--------------- ViewMover/ViewController.m | 27 ++++++++++++++++++--------- 2 files changed, 24 insertions(+), 24 deletions(-) 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]; }]; }