Skip to content

Now moves forward and back #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions ViewMover/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15C50" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand All @@ -20,7 +20,6 @@
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ndj-cl-KuB">
<rect key="frame" x="40" y="40" width="200" height="128"/>
<animations/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="b5R-Ja-Jt2"/>
Expand All @@ -29,29 +28,21 @@
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Fjl-dn-Sho">
<rect key="frame" x="262" y="517" width="75" height="30"/>
<animations/>
<state key="normal" title="Move View"/>
<connections>
<action selector="moveButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="orS-9d-lUG"/>
</connections>
</button>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="ndj-cl-KuB" secondAttribute="trailing" constant="20" id="2UI-mf-ijE"/>
<constraint firstItem="ndj-cl-KuB" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="20" id="8AD-wH-hGX"/>
<constraint firstAttribute="trailingMargin" secondItem="ndj-cl-KuB" secondAttribute="trailing" priority="250" constant="20" id="2UI-mf-ijE"/>
<constraint firstItem="ndj-cl-KuB" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" priority="750" constant="20" id="8AD-wH-hGX"/>
<constraint firstItem="Fjl-dn-Sho" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="ITK-oc-W9e"/>
<constraint firstItem="ndj-cl-KuB" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" constant="20" id="J1L-Bh-h3A"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="ndj-cl-KuB" secondAttribute="bottom" constant="208" id="ML2-cm-jJA"/>
<constraint firstItem="ndj-cl-KuB" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leadingMargin" priority="750" constant="20" id="J1L-Bh-h3A"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="ndj-cl-KuB" secondAttribute="bottom" priority="250" constant="208" id="ML2-cm-jJA"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="Fjl-dn-Sho" secondAttribute="bottom" constant="53" id="pzB-ps-Wm4"/>
</constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="2UI-mf-ijE"/>
<exclude reference="ML2-cm-jJA"/>
</mask>
</variation>
</view>
<connections>
<outlet property="bottomConstraint" destination="ML2-cm-jJA" id="5Vj-Ol-C7U"/>
Expand Down
27 changes: 18 additions & 9 deletions ViewMover/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}];
}
Expand Down