Skip to content

Commit 52df620

Browse files
committed
Added addRow() random with gallery vc in example app
1 parent 5ae92f7 commit 52df620

File tree

8 files changed

+209
-47
lines changed

8 files changed

+209
-47
lines changed

ScrollStackController.xcodeproj/project.pbxproj

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
64C0226F2347360800A6D844 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 64C0226D2347360800A6D844 /* Main.storyboard */; };
2626
64C022712347360900A6D844 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 64C022702347360900A6D844 /* Assets.xcassets */; };
2727
64C022742347360900A6D844 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 64C022722347360900A6D844 /* LaunchScreen.storyboard */; };
28-
64C0227D234753A100A6D844 /* VC1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0227C234753A100A6D844 /* VC1.swift */; };
28+
64C0227D234753A100A6D844 /* GalleryVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0227C234753A100A6D844 /* GalleryVC.swift */; };
2929
64C0227E2347582D00A6D844 /* ScrollStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02250234735A800A6D844 /* ScrollStack.swift */; };
3030
64C0227F2347582D00A6D844 /* ScrollStackRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02251234735A800A6D844 /* ScrollStackRow.swift */; };
3131
64C022812347582D00A6D844 /* ScrollStackSeparator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02252234735A800A6D844 /* ScrollStackSeparator.swift */; };
@@ -73,7 +73,7 @@
7373
64C022702347360900A6D844 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7474
64C022732347360900A6D844 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7575
64C022752347360900A6D844 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
76-
64C0227C234753A100A6D844 /* VC1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VC1.swift; sourceTree = "<group>"; };
76+
64C0227C234753A100A6D844 /* GalleryVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryVC.swift; sourceTree = "<group>"; };
7777
64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ScrollStack+Protocols.swift"; sourceTree = "<group>"; };
7878
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>"; };
@@ -162,6 +162,15 @@
162162
path = Support;
163163
sourceTree = "<group>";
164164
};
165+
64A8E8AF2348B02300E893FB /* Child View Controllers */ = {
166+
isa = PBXGroup;
167+
children = (
168+
64C0227C234753A100A6D844 /* GalleryVC.swift */,
169+
64C022892347834300A6D844 /* TagsVC.swift */,
170+
);
171+
path = "Child View Controllers";
172+
sourceTree = "<group>";
173+
};
165174
64C0224A2347358400A6D844 /* Sources */ = {
166175
isa = PBXGroup;
167176
children = (
@@ -185,13 +194,12 @@
185194
64C022662347360800A6D844 /* ScrollStackControllerDemo */ = {
186195
isa = PBXGroup;
187196
children = (
197+
64C0226D2347360800A6D844 /* Main.storyboard */,
188198
64C022672347360800A6D844 /* AppDelegate.swift */,
189199
64C022692347360800A6D844 /* SceneDelegate.swift */,
190200
64C0226B2347360800A6D844 /* ViewController.swift */,
191201
6402E1F12347A8540087963C /* Extension.swift */,
192-
64C0227C234753A100A6D844 /* VC1.swift */,
193-
64C022892347834300A6D844 /* TagsVC.swift */,
194-
64C0226D2347360800A6D844 /* Main.storyboard */,
202+
64A8E8AF2348B02300E893FB /* Child View Controllers */,
195203
64C022702347360900A6D844 /* Assets.xcassets */,
196204
64C022722347360900A6D844 /* LaunchScreen.storyboard */,
197205
64C022752347360900A6D844 /* Info.plist */,
@@ -468,7 +476,7 @@
468476
64C022682347360800A6D844 /* AppDelegate.swift in Sources */,
469477
6402E1F22347A8540087963C /* Extension.swift in Sources */,
470478
64C022832347582D00A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */,
471-
64C0227D234753A100A6D844 /* VC1.swift in Sources */,
479+
64C0227D234753A100A6D844 /* GalleryVC.swift in Sources */,
472480
64C0226A2347360800A6D844 /* SceneDelegate.swift in Sources */,
473481
);
474482
runOnlyForDeploymentPostprocessing = 0;

ScrollStackControllerDemo/Base.lproj/Main.storyboard

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
<constraint firstAttribute="width" constant="153" id="eZt-64-3CB"/>
2828
<constraint firstAttribute="height" constant="30" id="uxI-ig-f5J"/>
2929
</constraints>
30-
<state key="normal" title="Add new controller">
30+
<state key="normal" title="Add Random Row">
3131
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
3232
</state>
3333
<connections>
34-
<action selector="toggleAxis" destination="BYZ-38-t0r" eventType="touchUpInside" id="fsh-9U-1kD"/>
34+
<action selector="addNewRow" destination="BYZ-38-t0r" eventType="touchUpInside" id="O6D-J0-3dz"/>
3535
</connections>
3636
</button>
3737
</subviews>
@@ -54,31 +54,92 @@
5454
</objects>
5555
<point key="canvasLocation" x="-384.05797101449281" y="28.794642857142854"/>
5656
</scene>
57-
<!--VC1-->
57+
<!--GalleryVC-->
5858
<scene sceneID="F2C-MH-Lwo">
5959
<objects>
60-
<viewController storyboardIdentifier="VC1" id="hnx-R5-b6N" customClass="VC1" customModule="ScrollStackControllerDemo" customModuleProvider="target" sceneMemberID="viewController">
60+
<viewController storyboardIdentifier="GalleryVC" id="hnx-R5-b6N" customClass="GalleryVC" customModule="ScrollStackControllerDemo" customModuleProvider="target" sceneMemberID="viewController">
6161
<view key="view" contentMode="scaleToFill" id="aW5-uU-IfU">
6262
<rect key="frame" x="0.0" y="0.0" width="414" height="300"/>
6363
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
6464
<subviews>
65-
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yVI-0r-6fw">
66-
<rect key="frame" x="182.5" y="134.5" width="51" height="31"/>
67-
</switch>
65+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Gallery" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ljh-hs-c0p">
66+
<rect key="frame" x="20" y="20" width="374" height="29"/>
67+
<constraints>
68+
<constraint firstAttribute="height" constant="29" id="Myh-UV-YFF"/>
69+
</constraints>
70+
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="24"/>
71+
<nil key="textColor"/>
72+
<nil key="highlightedColor"/>
73+
</label>
74+
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" pagingEnabled="YES" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="6ap-K6-pdY">
75+
<rect key="frame" x="20" y="59" width="374" height="201"/>
76+
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
77+
<collectionViewFlowLayout key="collectionViewLayout" scrollDirection="horizontal" automaticEstimatedItemSize="YES" minimumLineSpacing="10" minimumInteritemSpacing="10" id="JHC-ZZ-rXC">
78+
<size key="itemSize" width="341" height="163"/>
79+
<size key="headerReferenceSize" width="0.0" height="0.0"/>
80+
<size key="footerReferenceSize" width="0.0" height="0.0"/>
81+
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
82+
</collectionViewFlowLayout>
83+
<cells>
84+
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="GalleryCell" id="oCT-2F-dbt" customClass="GalleryCell" customModule="ScrollStackControllerDemo" customModuleProvider="target">
85+
<rect key="frame" x="0.0" y="19" width="341" height="163"/>
86+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
87+
<collectionViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="RQp-h4-bd0">
88+
<rect key="frame" x="0.0" y="0.0" width="341" height="163"/>
89+
<autoresizingMask key="autoresizingMask"/>
90+
<subviews>
91+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="C5w-wr-ULb">
92+
<rect key="frame" x="0.0" y="0.0" width="341" height="163"/>
93+
</imageView>
94+
</subviews>
95+
<constraints>
96+
<constraint firstItem="C5w-wr-ULb" firstAttribute="top" secondItem="RQp-h4-bd0" secondAttribute="top" id="Uht-Pw-enC"/>
97+
<constraint firstAttribute="trailing" secondItem="C5w-wr-ULb" secondAttribute="trailing" id="Yy4-59-fe9"/>
98+
<constraint firstItem="C5w-wr-ULb" firstAttribute="leading" secondItem="RQp-h4-bd0" secondAttribute="leading" id="jdh-Gb-V7Y"/>
99+
<constraint firstAttribute="bottom" secondItem="C5w-wr-ULb" secondAttribute="bottom" id="n0B-qI-TNW"/>
100+
</constraints>
101+
</collectionViewCellContentView>
102+
<size key="customSize" width="341" height="163"/>
103+
<connections>
104+
<outlet property="imageView" destination="C5w-wr-ULb" id="dyu-bm-DIo"/>
105+
</connections>
106+
</collectionViewCell>
107+
</cells>
108+
<connections>
109+
<outlet property="dataSource" destination="hnx-R5-b6N" id="rgW-sY-0Rl"/>
110+
<outlet property="delegate" destination="hnx-R5-b6N" id="4nI-md-ZHb"/>
111+
</connections>
112+
</collectionView>
113+
<pageControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="nm5-iZ-3Pg">
114+
<rect key="frame" x="187.5" y="258" width="39" height="37"/>
115+
<color key="pageIndicatorTintColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
116+
<color key="currentPageIndicatorTintColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
117+
</pageControl>
68118
</subviews>
69-
<color key="backgroundColor" systemColor="systemOrangeColor" red="1" green="0.58431372550000005" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
119+
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
70120
<constraints>
71-
<constraint firstItem="yVI-0r-6fw" firstAttribute="centerX" secondItem="aW5-uU-IfU" secondAttribute="centerX" id="Mdn-9x-vmJ"/>
72-
<constraint firstItem="yVI-0r-6fw" firstAttribute="centerY" secondItem="aW5-uU-IfU" secondAttribute="centerY" id="yQs-O6-5Cr"/>
121+
<constraint firstItem="Ljh-hs-c0p" firstAttribute="leading" secondItem="aW5-uU-IfU" secondAttribute="leading" constant="20" id="8d4-tt-Why"/>
122+
<constraint firstItem="6ap-K6-pdY" firstAttribute="leading" secondItem="mC8-c9-Zzg" secondAttribute="leading" constant="20" id="K5f-cB-XOt"/>
123+
<constraint firstAttribute="trailing" secondItem="Ljh-hs-c0p" secondAttribute="trailing" constant="20" id="Rkb-0X-cdc"/>
124+
<constraint firstItem="Ljh-hs-c0p" firstAttribute="top" secondItem="aW5-uU-IfU" secondAttribute="top" constant="20" id="Wc3-fz-JMb"/>
125+
<constraint firstItem="6ap-K6-pdY" firstAttribute="top" secondItem="Ljh-hs-c0p" secondAttribute="bottom" constant="10" id="ctQ-DZ-iaQ"/>
126+
<constraint firstItem="nm5-iZ-3Pg" firstAttribute="centerX" secondItem="aW5-uU-IfU" secondAttribute="centerX" id="hWN-E2-vnV"/>
127+
<constraint firstItem="mC8-c9-Zzg" firstAttribute="bottom" secondItem="6ap-K6-pdY" secondAttribute="bottom" constant="40" id="jSU-H5-HbN"/>
128+
<constraint firstItem="mC8-c9-Zzg" firstAttribute="bottom" secondItem="nm5-iZ-3Pg" secondAttribute="bottom" constant="5" id="lXH-Ev-aez"/>
129+
<constraint firstItem="mC8-c9-Zzg" firstAttribute="trailing" secondItem="6ap-K6-pdY" secondAttribute="trailing" constant="20" id="mJt-La-Uf9"/>
73130
</constraints>
74131
<viewLayoutGuide key="safeArea" id="mC8-c9-Zzg"/>
75132
</view>
76133
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
77134
<size key="freeformSize" width="414" height="300"/>
135+
<connections>
136+
<outlet property="collectionView" destination="6ap-K6-pdY" id="qgm-nm-Jpi"/>
137+
<outlet property="pageControl" destination="nm5-iZ-3Pg" id="5hq-FL-Ppe"/>
138+
</connections>
78139
</viewController>
79140
<placeholder placeholderIdentifier="IBFirstResponder" id="i09-Qc-wUC" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
80141
</objects>
81-
<point key="canvasLocation" x="259" y="-171"/>
142+
<point key="canvasLocation" x="257.97101449275362" y="-171.42857142857142"/>
82143
</scene>
83144
<!--TagsVC-->
84145
<scene sceneID="W0p-QS-jfS">
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// GalleryVC.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 class GalleryVC: UIViewController, ScrollStackContainableController {
12+
13+
@IBOutlet public var collectionView: UICollectionView!
14+
@IBOutlet public var pageControl: UIPageControl!
15+
16+
public var urls: [URL] = [
17+
URL(string: "https://www.telegraph.co.uk/content/dam/Travel/2019/February/fuji.jpg?imwidth=450")!,
18+
URL(string: "https://japan-magazine.jnto.go.jp/jnto2wm/wp-content/uploads/1608_special_TOTO_main.jpg")!,
19+
URL(string: "https://millionmilesecrets.com/wp-content/uploads/Japan-Kyoto.jpg")!,
20+
URL(string: "https://media.cntraveller.in/wp-content/uploads/2019/07/Japan-leadraw-and-fine-866x487.jpg")!
21+
]
22+
23+
public static func create() -> GalleryVC {
24+
let storyboard = UIStoryboard(name: "Main", bundle: nil)
25+
let vc = storyboard.instantiateViewController(identifier: "GalleryVC") as! GalleryVC
26+
return vc
27+
}
28+
29+
public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? {
30+
return 300
31+
}
32+
33+
public override func viewDidAppear(_ animated: Bool) {
34+
super.viewDidAppear(animated)
35+
reloadData()
36+
}
37+
38+
public func reloadContentFromStackViewRow() {
39+
40+
}
41+
42+
private func reloadData() {
43+
pageControl.numberOfPages = urls.count
44+
collectionView.reloadData()
45+
}
46+
47+
}
48+
49+
extension GalleryVC: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
50+
51+
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
52+
return urls.count
53+
}
54+
55+
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
56+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "GalleryCell", for: indexPath) as! GalleryCell
57+
cell.url = urls[indexPath.item]
58+
return cell
59+
}
60+
61+
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
62+
return collectionView.bounds.size
63+
}
64+
65+
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
66+
return 0
67+
}
68+
69+
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
70+
return 0
71+
}
72+
73+
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
74+
return .zero
75+
}
76+
77+
78+
public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
79+
pageControl.currentPage = indexPath.item
80+
}
81+
82+
}
83+
84+
public class GalleryCell: UICollectionViewCell {
85+
86+
@IBOutlet public var imageView: UIImageView!
87+
88+
private var dataTask: URLSessionTask?
89+
90+
public var url: URL? {
91+
didSet {
92+
dataTask?.cancel()
93+
94+
guard let url = url else {
95+
self.imageView.image = nil
96+
return
97+
}
98+
99+
dataTask = URLSession.shared.dataTask(with: url) { (data, _, error) in
100+
let image = (data != nil ? UIImage(data: data!) : nil)
101+
DispatchQueue.main.async {
102+
self.imageView.image = image
103+
}
104+
}
105+
dataTask?.resume()
106+
}
107+
}
108+
109+
public override func prepareForReuse() {
110+
super.prepareForReuse()
111+
self.url = nil
112+
}
113+
114+
}

ScrollStackControllerDemo/TagsVC.swift renamed to ScrollStackControllerDemo/Child View Controllers/TagsVC.swift

File renamed without changes.

ScrollStackControllerDemo/Info.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<string>1</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
23+
<key>NSAppTransportSecurity</key>
24+
<dict>
25+
<key>NSAllowsArbitraryLoads</key>
26+
<true/>
27+
</dict>
2328
<key>UIApplicationSceneManifest</key>
2429
<dict>
2530
<key>UIApplicationSupportsMultipleScenes</key>

0 commit comments

Comments
 (0)