Skip to content

Commit fd3520f

Browse files
committed
add collapse/expand example
1 parent cd08cb6 commit fd3520f

File tree

12 files changed

+808
-0
lines changed

12 files changed

+808
-0
lines changed

bk2ch04p183animationAndAutolayout4/Expandable.xcodeproj/project.pbxproj

Lines changed: 438 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
#import <UIKit/UIKit.h>
3+
4+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
5+
6+
@property (strong, nonatomic) UIWindow *window;
7+
8+
9+
@end
10+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
#import "AppDelegate.h"
4+
5+
@interface AppDelegate ()
6+
7+
@end
8+
9+
@implementation AppDelegate
10+
11+
12+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
13+
// Override point for customization after application launch.
14+
return YES;
15+
}
16+
17+
18+
@end
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
5+
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
6+
</dependencies>
7+
<objects>
8+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
9+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
10+
<view contentMode="scaleToFill" id="iN0-l3-epB">
11+
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
12+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
13+
<subviews>
14+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Kevin Sylvestre. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
15+
<rect key="frame" x="20" y="439" width="441" height="21"/>
16+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
17+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
18+
<nil key="highlightedColor"/>
19+
</label>
20+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Expandable" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
21+
<rect key="frame" x="20" y="140" width="441" height="43"/>
22+
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
23+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
24+
<nil key="highlightedColor"/>
25+
</label>
26+
</subviews>
27+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
28+
<constraints>
29+
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
30+
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
31+
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
32+
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
33+
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
34+
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
35+
</constraints>
36+
<nil key="simulatedStatusBarMetrics"/>
37+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
38+
<point key="canvasLocation" x="548" y="455"/>
39+
</view>
40+
</objects>
41+
</document>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
5+
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
6+
</dependencies>
7+
<scenes>
8+
<!--View Controller-->
9+
<scene sceneID="ufC-wZ-h7g">
10+
<objects>
11+
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="Expandable" customModuleProvider="target" sceneMemberID="viewController">
12+
<layoutGuides>
13+
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
14+
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
15+
</layoutGuides>
16+
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
17+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
18+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
19+
<subviews>
20+
<view clipsSubviews="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="b7f-dR-P5z" userLabel="View - Content">
21+
<rect key="frame" x="0.0" y="40" width="600" height="257"/>
22+
<subviews>
23+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Header" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NcT-xh-dCy" userLabel="Label - Header">
24+
<rect key="frame" x="16" y="16" width="568" height="77"/>
25+
<color key="backgroundColor" red="0.90196079015731812" green="0.90196079015731812" blue="0.90196079015731812" alpha="1" colorSpace="calibratedRGB"/>
26+
<fontDescription key="fontDescription" type="system" pointSize="64"/>
27+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
28+
<nil key="highlightedColor"/>
29+
</label>
30+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="This text can expand and collapse" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="d71-04-56d" userLabel="Label - Random">
31+
<rect key="frame" x="16" y="109" width="568" height="39"/>
32+
<fontDescription key="fontDescription" type="system" pointSize="32"/>
33+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
34+
<nil key="highlightedColor"/>
35+
</label>
36+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Footer" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="W6F-ti-jtW" userLabel="Label - Footer">
37+
<rect key="frame" x="16" y="164" width="568" height="77"/>
38+
<color key="backgroundColor" red="0.80000001192092896" green="0.80000001192092896" blue="0.80000001192092896" alpha="1" colorSpace="calibratedRGB"/>
39+
<fontDescription key="fontDescription" type="system" pointSize="64"/>
40+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
41+
<nil key="highlightedColor"/>
42+
</label>
43+
</subviews>
44+
<color key="backgroundColor" red="1" green="0.50196081399917603" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
45+
<constraints>
46+
<constraint firstItem="d71-04-56d" firstAttribute="leading" secondItem="b7f-dR-P5z" secondAttribute="leading" constant="16" id="7mQ-Lo-F5d"/>
47+
<constraint firstAttribute="height" priority="250" constant="257" id="ACc-zt-wgN"/>
48+
<constraint firstItem="W6F-ti-jtW" firstAttribute="leading" secondItem="b7f-dR-P5z" secondAttribute="leading" constant="16" id="S3V-a7-nRN"/>
49+
<constraint firstAttribute="trailing" secondItem="NcT-xh-dCy" secondAttribute="trailing" constant="16" id="Url-hR-du1"/>
50+
<constraint firstItem="NcT-xh-dCy" firstAttribute="top" secondItem="b7f-dR-P5z" secondAttribute="top" constant="16" id="eQE-Me-OZP"/>
51+
<constraint firstItem="d71-04-56d" firstAttribute="top" secondItem="NcT-xh-dCy" secondAttribute="bottom" constant="16" id="fsW-FE-8ZI"/>
52+
<constraint firstItem="W6F-ti-jtW" firstAttribute="top" secondItem="d71-04-56d" secondAttribute="bottom" constant="16" id="oH7-29-KnE"/>
53+
<constraint firstItem="NcT-xh-dCy" firstAttribute="leading" secondItem="b7f-dR-P5z" secondAttribute="leading" constant="16" id="rml-f0-A21"/>
54+
<constraint firstAttribute="trailing" secondItem="d71-04-56d" secondAttribute="trailing" constant="16" id="scz-73-FEC"/>
55+
<constraint firstAttribute="bottom" secondItem="W6F-ti-jtW" secondAttribute="bottom" constant="16" id="w6U-HI-STy"/>
56+
<constraint firstAttribute="trailing" secondItem="W6F-ti-jtW" secondAttribute="trailing" constant="16" id="xY2-yv-uQB"/>
57+
</constraints>
58+
</view>
59+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RkA-qd-feC">
60+
<rect key="frame" x="16" y="337" width="568" height="30"/>
61+
<state key="normal" title="Toggle Section">
62+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
63+
</state>
64+
<connections>
65+
<action selector="toggleButtonSelector:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="9P8-t2-giV"/>
66+
</connections>
67+
</button>
68+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="74d-Ly-mGp">
69+
<rect key="frame" x="16" y="391" width="568" height="30"/>
70+
<state key="normal" title="Toggle Contents">
71+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
72+
</state>
73+
<connections>
74+
<action selector="toggleContents:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Nr7-Go-s3j"/>
75+
</connections>
76+
</button>
77+
</subviews>
78+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
79+
<constraints>
80+
<constraint firstItem="b7f-dR-P5z" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="20" id="JVb-nY-dWE"/>
81+
<constraint firstItem="RkA-qd-feC" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="16" id="aK6-yG-ZTS"/>
82+
<constraint firstAttribute="trailing" secondItem="RkA-qd-feC" secondAttribute="trailing" constant="16" id="fUp-27-6n9"/>
83+
<constraint firstItem="74d-Ly-mGp" firstAttribute="top" secondItem="RkA-qd-feC" secondAttribute="bottom" constant="24" id="hc6-6J-N6V"/>
84+
<constraint firstItem="74d-Ly-mGp" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" id="ic6-7e-vrz"/>
85+
<constraint firstAttribute="trailingMargin" secondItem="74d-Ly-mGp" secondAttribute="trailing" id="jVE-Hn-cKj"/>
86+
<constraint firstAttribute="trailing" secondItem="b7f-dR-P5z" secondAttribute="trailing" id="rfE-kd-6lB"/>
87+
<constraint firstItem="b7f-dR-P5z" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" id="vs3-zc-4U4"/>
88+
<constraint firstItem="RkA-qd-feC" firstAttribute="top" secondItem="b7f-dR-P5z" secondAttribute="bottom" constant="40" id="yLK-6d-qzl"/>
89+
</constraints>
90+
</view>
91+
<connections>
92+
<outlet property="bottomInternalConstraint" destination="w6U-HI-STy" id="SeC-qj-emF"/>
93+
<outlet property="randomLabel" destination="d71-04-56d" id="Bzb-07-BQQ"/>
94+
<outlet property="sectionHeightConstraint" destination="ACc-zt-wgN" id="6Cy-9c-QHd"/>
95+
</connections>
96+
</viewController>
97+
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
98+
</objects>
99+
</scene>
100+
</scenes>
101+
</document>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"size" : "29x29",
6+
"scale" : "2x"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"size" : "29x29",
11+
"scale" : "3x"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"size" : "40x40",
16+
"scale" : "2x"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"size" : "40x40",
21+
"scale" : "3x"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"size" : "60x60",
26+
"scale" : "2x"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"size" : "60x60",
31+
"scale" : "3x"
32+
}
33+
],
34+
"info" : {
35+
"version" : 1,
36+
"author" : "xcode"
37+
}
38+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>com.ksylvest.$(PRODUCT_NAME:rfc1034identifier)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSRequiresIPhoneOS</key>
24+
<true/>
25+
<key>UILaunchStoryboardName</key>
26+
<string>LaunchScreen</string>
27+
<key>UIMainStoryboardFile</key>
28+
<string>Main</string>
29+
<key>UIRequiredDeviceCapabilities</key>
30+
<array>
31+
<string>armv7</string>
32+
</array>
33+
<key>UISupportedInterfaceOrientations</key>
34+
<array>
35+
<string>UIInterfaceOrientationPortrait</string>
36+
<string>UIInterfaceOrientationLandscapeLeft</string>
37+
<string>UIInterfaceOrientationLandscapeRight</string>
38+
</array>
39+
</dict>
40+
</plist>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
3+
import UIKit
4+
5+
class ViewController : UIViewController {
6+
@IBOutlet var randomLabel : UILabel!
7+
@IBOutlet var sectionHeightConstraint : NSLayoutConstraint!
8+
@IBOutlet var bottomInternalConstraint : NSLayoutConstraint!
9+
var collapsed = false
10+
let texts = ["This text can expand and collapse", "The quick brown fox jumps over the lazy dog. Then he went on vacation... Then he had a drink..."]
11+
var long = false
12+
13+
@IBAction func toggleContents(sender: AnyObject!) {
14+
self.long = !self.long
15+
self.randomLabel.text = self.texts[self.long ? 1 : 0]
16+
17+
}
18+
19+
@IBAction func toggleButtonSelector (sender:AnyObject!) {
20+
self.collapsed = !self.collapsed
21+
if self.collapsed {
22+
self.sectionHeightConstraint.constant = 10
23+
self.sectionHeightConstraint.priority = 999
24+
NSLayoutConstraint.deactivateConstraints([self.bottomInternalConstraint])
25+
UIView.animateWithDuration(1) {
26+
self.view.layoutIfNeeded()
27+
}
28+
29+
} else {
30+
self.sectionHeightConstraint.priority = 250
31+
NSLayoutConstraint.activateConstraints([self.bottomInternalConstraint])
32+
UIView.animateWithDuration(1) {
33+
self.view.layoutIfNeeded()
34+
}
35+
}
36+
}
37+
38+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// main.m
3+
// Expandable
4+
//
5+
// Created by Kevin Sylvestre on 2015-04-17.
6+
// Copyright (c) 2015 Kevin Sylvestre. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "AppDelegate.h"
11+
12+
int main(int argc, char * argv[]) {
13+
@autoreleasepool {
14+
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15+
}
16+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// ExpandableTests.m
3+
// ExpandableTests
4+
//
5+
// Created by Kevin Sylvestre on 2015-04-17.
6+
// Copyright (c) 2015 Kevin Sylvestre. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import <XCTest/XCTest.h>
11+
12+
@interface ExpandableTests : XCTestCase
13+
14+
@end
15+
16+
@implementation ExpandableTests
17+
18+
- (void)setUp {
19+
[super setUp];
20+
// Put setup code here. This method is called before the invocation of each test method in the class.
21+
}
22+
23+
- (void)tearDown {
24+
// Put teardown code here. This method is called after the invocation of each test method in the class.
25+
[super tearDown];
26+
}
27+
28+
- (void)testExample {
29+
// This is an example of a functional test case.
30+
XCTAssert(YES, @"Pass");
31+
}
32+
33+
- (void)testPerformanceExample {
34+
// This is an example of a performance test case.
35+
[self measureBlock:^{
36+
// Put the code you want to measure the time of here.
37+
}];
38+
}
39+
40+
@end

0 commit comments

Comments
 (0)