Skip to content

Commit 5ae92f7

Browse files
committed
Working on example app. Added functionality to show expand/collapse of the view controllers
1 parent 76f27a6 commit 5ae92f7

File tree

6 files changed

+207
-57
lines changed

6 files changed

+207
-57
lines changed

ScrollStackController.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
64C0228623475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */; };
3535
64C0228723475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */; };
3636
64C0228823475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */; };
37-
64C0228A2347834300A6D844 /* VC2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C022892347834300A6D844 /* VC2.swift */; };
37+
64C0228A2347834300A6D844 /* TagsVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C022892347834300A6D844 /* TagsVC.swift */; };
3838
DD7502921C690C7A006590AF /* ScrollStackController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D9F01BEFFFBE002C0205 /* ScrollStackController.framework */; };
3939
/* End PBXBuildFile section */
4040

@@ -75,7 +75,7 @@
7575
64C022752347360900A6D844 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7676
64C0227C234753A100A6D844 /* VC1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VC1.swift; sourceTree = "<group>"; };
7777
64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ScrollStack+Protocols.swift"; sourceTree = "<group>"; };
78-
64C022892347834300A6D844 /* VC2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VC2.swift; sourceTree = "<group>"; };
78+
64C022892347834300A6D844 /* TagsVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsVC.swift; sourceTree = "<group>"; };
7979
AD2FAA261CD0B6D800659CF4 /* ScrollStackController.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ScrollStackController.plist; sourceTree = "<group>"; };
8080
AD2FAA281CD0B6E100659CF4 /* ScrollStackControllerTests.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ScrollStackControllerTests.plist; sourceTree = "<group>"; };
8181
DD75028D1C690C7A006590AF /* ScrollStackController-tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "ScrollStackController-tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -190,7 +190,7 @@
190190
64C0226B2347360800A6D844 /* ViewController.swift */,
191191
6402E1F12347A8540087963C /* Extension.swift */,
192192
64C0227C234753A100A6D844 /* VC1.swift */,
193-
64C022892347834300A6D844 /* VC2.swift */,
193+
64C022892347834300A6D844 /* TagsVC.swift */,
194194
64C0226D2347360800A6D844 /* Main.storyboard */,
195195
64C022702347360900A6D844 /* Assets.xcassets */,
196196
64C022722347360900A6D844 /* LaunchScreen.storyboard */,
@@ -460,7 +460,7 @@
460460
files = (
461461
64C0228823475A0E00A6D844 /* ScrollStack+Protocols.swift in Sources */,
462462
64C0227F2347582D00A6D844 /* ScrollStackRow.swift in Sources */,
463-
64C0228A2347834300A6D844 /* VC2.swift in Sources */,
463+
64C0228A2347834300A6D844 /* TagsVC.swift in Sources */,
464464
64C022822347582D00A6D844 /* ScrollStackViewController.swift in Sources */,
465465
64C0226C2347360800A6D844 /* ViewController.swift in Sources */,
466466
64C022812347582D00A6D844 /* ScrollStackSeparator.swift in Sources */,

ScrollStackControllerDemo/Base.lproj/Main.storyboard

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<dependencies>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
66
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7+
<capability name="collection view cell content view" minToolsVersion="11.0"/>
78
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
89
</dependencies>
910
<scenes>
@@ -79,34 +80,115 @@
7980
</objects>
8081
<point key="canvasLocation" x="259" y="-171"/>
8182
</scene>
82-
<!--VC2-->
83+
<!--TagsVC-->
8384
<scene sceneID="W0p-QS-jfS">
8485
<objects>
85-
<viewController storyboardIdentifier="VC2" id="1Ap-wi-SGJ" customClass="VC2" customModule="ScrollStackControllerDemo" customModuleProvider="target" sceneMemberID="viewController">
86-
<view key="view" contentMode="scaleToFill" id="dZN-dE-Enp">
86+
<viewController storyboardIdentifier="TagsVC" id="1Ap-wi-SGJ" customClass="TagsVC" customModule="ScrollStackControllerDemo" customModuleProvider="target" sceneMemberID="viewController">
87+
<view key="view" clipsSubviews="YES" contentMode="scaleToFill" id="dZN-dE-Enp">
8788
<rect key="frame" x="0.0" y="0.0" width="414" height="300"/>
8889
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
8990
<subviews>
90-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Welcome to Home" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PXE-1E-oq8">
91-
<rect key="frame" x="20" y="20" width="374" height="25.5"/>
92-
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="21"/>
91+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tags" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PXE-1E-oq8">
92+
<rect key="frame" x="20" y="20" width="374" height="29"/>
93+
<constraints>
94+
<constraint firstAttribute="height" constant="29" id="AIx-ke-Tgj"/>
95+
</constraints>
96+
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="24"/>
97+
<nil key="textColor"/>
98+
<nil key="highlightedColor"/>
99+
</label>
100+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="The list of tags identify the main features of the hotel and allows you have an overlook of the structure." textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="07k-I9-iAh">
101+
<rect key="frame" x="20" y="59" width="374" height="31.5"/>
102+
<fontDescription key="fontDescription" type="system" pointSize="13"/>
93103
<nil key="textColor"/>
94104
<nil key="highlightedColor"/>
95105
</label>
106+
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="hEu-BP-BEf">
107+
<rect key="frame" x="20" y="158.5" width="374" height="121.5"/>
108+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
109+
<constraints>
110+
<constraint firstAttribute="height" constant="121.5" id="vk7-Vr-uiW"/>
111+
</constraints>
112+
<collectionViewFlowLayout key="collectionViewLayout" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="Rd2-UE-99o">
113+
<size key="itemSize" width="127" height="39"/>
114+
<size key="headerReferenceSize" width="0.0" height="0.0"/>
115+
<size key="footerReferenceSize" width="0.0" height="0.0"/>
116+
<inset key="sectionInset" minX="3" minY="3" maxX="3" maxY="3"/>
117+
</collectionViewFlowLayout>
118+
<cells>
119+
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="TagsCell" id="U7u-4F-pxk" customClass="TagsCell" customModule="ScrollStackControllerDemo" customModuleProvider="target">
120+
<rect key="frame" x="3" y="3" width="127" height="39"/>
121+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
122+
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="jiz-E0-cdi">
123+
<rect key="frame" x="0.0" y="0.0" width="127" height="39"/>
124+
<autoresizingMask key="autoresizingMask"/>
125+
<subviews>
126+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="tag 1" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3iw-Le-DPp">
127+
<rect key="frame" x="5" y="5" width="117" height="29"/>
128+
<fontDescription key="fontDescription" type="system" pointSize="12"/>
129+
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
130+
<nil key="highlightedColor"/>
131+
</label>
132+
</subviews>
133+
<constraints>
134+
<constraint firstItem="3iw-Le-DPp" firstAttribute="leading" secondItem="jiz-E0-cdi" secondAttribute="leading" constant="5" id="DdG-nS-LHw"/>
135+
<constraint firstAttribute="trailing" secondItem="3iw-Le-DPp" secondAttribute="trailing" constant="5" id="Wl8-kR-Xm0"/>
136+
<constraint firstItem="3iw-Le-DPp" firstAttribute="top" secondItem="jiz-E0-cdi" secondAttribute="top" constant="5" id="r9L-Ja-E3c"/>
137+
<constraint firstAttribute="bottom" secondItem="3iw-Le-DPp" secondAttribute="bottom" constant="5" id="xIL-HU-nTp"/>
138+
</constraints>
139+
</collectionViewCellContentView>
140+
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
141+
<size key="customSize" width="127" height="39"/>
142+
<connections>
143+
<outlet property="labelCell" destination="3iw-Le-DPp" id="9kS-ar-oRP"/>
144+
</connections>
145+
</collectionViewCell>
146+
</cells>
147+
<connections>
148+
<outlet property="dataSource" destination="1Ap-wi-SGJ" id="lgH-Bi-HUt"/>
149+
<outlet property="delegate" destination="1Ap-wi-SGJ" id="EN8-bJ-ou5"/>
150+
</connections>
151+
</collectionView>
152+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Pvd-nH-BQb">
153+
<rect key="frame" x="157" y="105.5" width="100" height="33"/>
154+
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
155+
<constraints>
156+
<constraint firstAttribute="width" constant="100" id="gpv-3A-vWT"/>
157+
<constraint firstAttribute="height" constant="33" id="tqa-oJ-5Mh"/>
158+
</constraints>
159+
<state key="normal" title="Show Tags">
160+
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
161+
</state>
162+
<connections>
163+
<action selector="toggleTags" destination="1Ap-wi-SGJ" eventType="touchUpInside" id="tqB-sm-cF6"/>
164+
</connections>
165+
</button>
96166
</subviews>
97167
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
98168
<constraints>
169+
<constraint firstItem="07k-I9-iAh" firstAttribute="leading" secondItem="N9x-T6-Cli" secondAttribute="leading" constant="20" id="54C-zU-Mai"/>
170+
<constraint firstItem="N9x-T6-Cli" firstAttribute="trailing" secondItem="07k-I9-iAh" secondAttribute="trailing" constant="20" id="7pH-kL-R7f"/>
171+
<constraint firstItem="N9x-T6-Cli" firstAttribute="trailing" secondItem="hEu-BP-BEf" secondAttribute="trailing" constant="20" id="TMR-JB-tA9"/>
172+
<constraint firstItem="Pvd-nH-BQb" firstAttribute="centerX" secondItem="dZN-dE-Enp" secondAttribute="centerX" id="isB-2H-FPp"/>
99173
<constraint firstItem="PXE-1E-oq8" firstAttribute="leading" secondItem="N9x-T6-Cli" secondAttribute="leading" constant="20" id="lCR-B8-Ec4"/>
174+
<constraint firstItem="hEu-BP-BEf" firstAttribute="top" secondItem="Pvd-nH-BQb" secondAttribute="bottom" constant="20" id="oj6-gT-ivI"/>
175+
<constraint firstItem="07k-I9-iAh" firstAttribute="top" secondItem="PXE-1E-oq8" secondAttribute="bottom" constant="10" id="s5i-zk-cs0"/>
100176
<constraint firstItem="N9x-T6-Cli" firstAttribute="trailing" secondItem="PXE-1E-oq8" secondAttribute="trailing" constant="20" id="tad-L3-w90"/>
101177
<constraint firstItem="PXE-1E-oq8" firstAttribute="top" secondItem="dZN-dE-Enp" secondAttribute="top" constant="20" id="ufn-3x-2ZS"/>
178+
<constraint firstItem="hEu-BP-BEf" firstAttribute="leading" secondItem="N9x-T6-Cli" secondAttribute="leading" constant="20" id="uhR-FS-S6k"/>
179+
<constraint firstItem="Pvd-nH-BQb" firstAttribute="top" secondItem="07k-I9-iAh" secondAttribute="bottom" constant="15" id="vDc-QF-RcJ"/>
102180
</constraints>
103181
<viewLayoutGuide key="safeArea" id="N9x-T6-Cli"/>
104182
</view>
105183
<size key="freeformSize" width="414" height="300"/>
184+
<connections>
185+
<outlet property="collectionView" destination="hEu-BP-BEf" id="b49-r3-uUw"/>
186+
<outlet property="toggleTagsButton" destination="Pvd-nH-BQb" id="RQu-uH-Yv0"/>
187+
</connections>
106188
</viewController>
107189
<placeholder placeholderIdentifier="IBFirstResponder" id="XEK-KL-pKN" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
108190
</objects>
109-
<point key="canvasLocation" x="257.97101449275362" y="76.339285714285708"/>
191+
<point key="canvasLocation" x="257.97101449275362" y="73.660714285714278"/>
110192
</scene>
111193
</scenes>
112194
</document>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//
2+
// TagsVC.swift
3+
// ScrollStackControllerDemo
4+
//
5+
// Created by Daniele Margutti on 04/10/2019.
6+
// Copyright © 2019 ScrollStackController. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
public protocol TagsVCProtocol: class {
12+
func toggleTags()
13+
}
14+
15+
public class TagsVC: UIViewController, ScrollStackContainableController {
16+
17+
@IBOutlet public var collectionView: UICollectionView!
18+
@IBOutlet public var toggleTagsButton: UIButton!
19+
20+
private weak var delegate: TagsVCProtocol?
21+
22+
private var tags: [String] = [
23+
"swimming pool",
24+
"kitchen",
25+
"terrace",
26+
"bathtub",
27+
"A/C",
28+
"parking",
29+
"pet friendly",
30+
"relax spa",
31+
"private bathroom",
32+
"cafe"
33+
]
34+
35+
public var isExpanded = false {
36+
didSet {
37+
if isExpanded {
38+
collectionView.height(constant: collectionView.contentSize.height)
39+
}
40+
updateUI()
41+
}
42+
}
43+
44+
public static func create(delegate: TagsVCProtocol) -> TagsVC {
45+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
46+
let vc = storyboard.instantiateViewController(identifier: "TagsVC") as! TagsVC
47+
vc.view.backgroundColor = UIColor.random()
48+
vc.delegate = delegate
49+
return vc
50+
}
51+
52+
public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? {
53+
return (isExpanded == false ? 170 : 170 + collectionView.contentSize.height + 20)
54+
}
55+
56+
public func reloadContentFromStackViewRow() {
57+
58+
}
59+
60+
public override func viewDidLoad() {
61+
super.viewDidLoad()
62+
collectionView.reloadData()
63+
updateUI()
64+
}
65+
66+
@IBAction public func toggleTags() {
67+
delegate?.toggleTags()
68+
}
69+
70+
private func updateUI() {
71+
toggleTagsButton.setTitle( (isExpanded ? "Hide Tags" : "Show Tags"), for: .normal)
72+
}
73+
74+
}
75+
76+
extension TagsVC: UICollectionViewDataSource {
77+
78+
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
79+
return tags.count
80+
}
81+
82+
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
83+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagsCell", for: indexPath) as! TagsCell
84+
cell.labelCell.text = tags[indexPath.item]
85+
return cell
86+
}
87+
88+
}
89+
90+
public class TagsCell: UICollectionViewCell {
91+
92+
@IBOutlet public var labelCell: UILabel!
93+
94+
}

ScrollStackControllerDemo/VC2.swift

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)