Skip to content

Commit 503b157

Browse files
committed
🤔WIP [ci skip]
1 parent 4ac137f commit 503b157

File tree

4 files changed

+180
-18
lines changed

4 files changed

+180
-18
lines changed
Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="7T2-uk-2HS">
33
<dependencies>
44
<deployment identifier="iOS"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
@@ -15,28 +15,44 @@
1515
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1616
</layoutGuides>
1717
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
18+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
19+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
21+
</view>
22+
</viewController>
23+
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
24+
</objects>
25+
<point key="canvasLocation" x="793" y="142"/>
26+
</scene>
27+
<!--View Controller-->
28+
<scene sceneID="J1t-eD-mqX">
29+
<objects>
30+
<viewController id="7T2-uk-2HS" sceneMemberID="viewController">
31+
<layoutGuides>
32+
<viewControllerLayoutGuide type="top" id="t5A-zv-W6A"/>
33+
<viewControllerLayoutGuide type="bottom" id="Ief-Ba-u8T"/>
34+
</layoutGuides>
35+
<view key="view" contentMode="scaleToFill" id="kwf-cN-PbM">
1836
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1937
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2038
<subviews>
21-
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="1Zb-nQ-PZ0" customClass="StackScrollView" customModule="StackScrollView">
22-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
23-
</view>
39+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XRJ-Za-6jO">
40+
<state key="normal" title="Button"/>
41+
<connections>
42+
<segue destination="BYZ-38-t0r" kind="presentation" id="P88-30-pnT"/>
43+
</connections>
44+
</button>
2445
</subviews>
25-
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
46+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
2647
<constraints>
27-
<constraint firstAttribute="bottom" secondItem="1Zb-nQ-PZ0" secondAttribute="bottom" id="NOz-JJ-Ug8"/>
28-
<constraint firstItem="1Zb-nQ-PZ0" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="Wh8-iT-gKd"/>
29-
<constraint firstAttribute="trailing" secondItem="1Zb-nQ-PZ0" secondAttribute="trailing" id="ZLv-iv-Ve3"/>
30-
<constraint firstItem="1Zb-nQ-PZ0" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="a0d-hy-j9C"/>
48+
<constraint firstItem="XRJ-Za-6jO" firstAttribute="centerX" secondItem="kwf-cN-PbM" secondAttribute="centerX" id="fzA-0K-SDX"/>
49+
<constraint firstItem="XRJ-Za-6jO" firstAttribute="centerY" secondItem="kwf-cN-PbM" secondAttribute="centerY" id="pKu-OC-NnY"/>
3150
</constraints>
3251
</view>
33-
<connections>
34-
<outlet property="stackScrollView" destination="1Zb-nQ-PZ0" id="H30-gJ-GhA"/>
35-
</connections>
3652
</viewController>
37-
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
53+
<placeholder placeholderIdentifier="IBFirstResponder" id="Vy7-aX-cKh" userLabel="First Responder" sceneMemberID="firstResponder"/>
3854
</objects>
39-
<point key="canvasLocation" x="-58.399999999999999" y="131.78410794602701"/>
55+
<point key="canvasLocation" x="20" y="142"/>
4056
</scene>
4157
</scenes>
4258
</document>

StackScrollView-Demo/ViewController.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,34 @@ class ViewController: UIViewController {
5151
}
5252
}
5353

54+
let cells = (0...50).map { i -> LabelStackViewCell in
55+
LabelStackViewCell().then { cell in
56+
cell.backgroundColor = colorA
57+
cell.titleLabel.text = "\(i)"
58+
cell.detailLabel.text = "\(i)"
59+
}
60+
}
61+
5462
stackScrollView.append(
5563
views: [
5664
labelCell,
5765
switchCell,
5866
labelFromTextCell,
5967
textFieldCell,
60-
],
61-
animated: true)
68+
] + cells,
69+
animated: false)
70+
71+
stackScrollView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
72+
stackScrollView.frame = view.bounds
73+
view.addSubview(stackScrollView)
6274
}
6375

6476
override func didReceiveMemoryWarning() {
6577
super.didReceiveMemoryWarning()
6678
// Dispose of any resources that can be recreated.
6779
}
6880

69-
@IBOutlet weak var stackScrollView: StackScrollView!
81+
private var stackScrollView = BetaStackScrollView()
7082
}
7183

7284
class LabelStackViewCell: UIView {

StackScrollView.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
4B6C2DB71D8DA68E003D3A46 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B6C2DB51D8DA68E003D3A46 /* Main.storyboard */; };
1717
4B6C2DB91D8DA68E003D3A46 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B6C2DB81D8DA68E003D3A46 /* Assets.xcassets */; };
1818
4B6C2DBC1D8DA68E003D3A46 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B6C2DBA1D8DA68E003D3A46 /* LaunchScreen.storyboard */; };
19+
4BDB87D71DBFB49500E70D5B /* BetaStackScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BDB87D61DBFB49500E70D5B /* BetaStackScrollView.swift */; };
1920
4BE8B6ED1D8E5A9700A4DC33 /* StackScrollView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B6C2D991D8DA3FB003D3A46 /* StackScrollView.framework */; };
2021
4BE8B6EE1D8E5A9700A4DC33 /* StackScrollView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4B6C2D991D8DA3FB003D3A46 /* StackScrollView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2122
4BE8B6F61D8E5AF200A4DC33 /* Then.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE8B6F51D8E5AF200A4DC33 /* Then.framework */; };
@@ -64,6 +65,7 @@
6465
4B6C2DB81D8DA68E003D3A46 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
6566
4B6C2DBB1D8DA68E003D3A46 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
6667
4B6C2DBD1D8DA68E003D3A46 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
68+
4BDB87D61DBFB49500E70D5B /* BetaStackScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BetaStackScrollView.swift; sourceTree = "<group>"; };
6769
4BE8B6F51D8E5AF200A4DC33 /* Then.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Then.framework; path = Carthage/Build/iOS/Then.framework; sourceTree = "<group>"; };
6870
/* End PBXFileReference section */
6971

@@ -112,6 +114,7 @@
112114
isa = PBXGroup;
113115
children = (
114116
4B6C2DA41D8DA42A003D3A46 /* StackScrollView.swift */,
117+
4BDB87D61DBFB49500E70D5B /* BetaStackScrollView.swift */,
115118
4B6C2DA51D8DA42A003D3A46 /* StackScrollViewCellType.swift */,
116119
4B6C2D9C1D8DA3FB003D3A46 /* StackScrollView.h */,
117120
4B6C2D9D1D8DA3FB003D3A46 /* Info.plist */,
@@ -261,6 +264,7 @@
261264
buildActionMask = 2147483647;
262265
files = (
263266
4B6C2DA71D8DA42A003D3A46 /* StackScrollViewCellType.swift in Sources */,
267+
4BDB87D71DBFB49500E70D5B /* BetaStackScrollView.swift in Sources */,
264268
4B6C2DA61D8DA42A003D3A46 /* StackScrollView.swift in Sources */,
265269
);
266270
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
//
2+
// _StackScrollView.swift
3+
// StackScrollView
4+
//
5+
// Created by muukii on 2016/10/26.
6+
// Copyright © 2016 muukii. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol _StackScrollViewCellType {
12+
13+
}
14+
15+
open class BetaStackScrollView: UIView, UITableViewDataSource, UITableViewDelegate {
16+
17+
public override init(frame: CGRect) {
18+
19+
super.init(frame: frame)
20+
setup()
21+
}
22+
23+
public required init?(coder aDecoder: NSCoder) {
24+
25+
super.init(coder: aDecoder)
26+
setup()
27+
}
28+
29+
open func setup() {
30+
31+
tableView.backgroundColor = UIColor.clear
32+
tableView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
33+
tableView.frame = bounds
34+
35+
addSubview(tableView)
36+
}
37+
38+
open override func didMoveToSuperview() {
39+
super.didMoveToSuperview()
40+
if superview != nil {
41+
tableView.delegate = self
42+
tableView.dataSource = self
43+
}
44+
}
45+
46+
open func append(view: UIView, animated: Bool) {
47+
48+
let cell = UITableViewCell(frame: .zero)
49+
let contentView = cell.contentView
50+
view.translatesAutoresizingMaskIntoConstraints = false
51+
contentView.addSubview(view)
52+
NSLayoutConstraint.activate([
53+
NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .top, multiplier: 1, constant: 0),
54+
NSLayoutConstraint(item: view, attribute: .right, relatedBy: .equal, toItem: contentView, attribute: .right, multiplier: 1, constant: 0),
55+
NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: contentView, attribute: .bottom, multiplier: 1, constant: 0),
56+
NSLayoutConstraint(item: view, attribute: .left, relatedBy: .equal, toItem: contentView, attribute: .left, multiplier: 1, constant: 0),
57+
])
58+
cells.append(cell)
59+
60+
// TODO: Improve performance, animated
61+
tableView.reloadData()
62+
}
63+
64+
open func append(views: [UIView], animated: Bool) {
65+
66+
let _cells = views.map { view -> UITableViewCell in
67+
let cell = UITableViewCell(frame: .zero)
68+
let contentView = cell.contentView
69+
view.translatesAutoresizingMaskIntoConstraints = false
70+
contentView.addSubview(view)
71+
NSLayoutConstraint.activate([
72+
NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .top, multiplier: 1, constant: 0),
73+
NSLayoutConstraint(item: view, attribute: .right, relatedBy: .equal, toItem: contentView, attribute: .right, multiplier: 1, constant: 0),
74+
NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: contentView, attribute: .bottom, multiplier: 1, constant: 0),
75+
NSLayoutConstraint(item: view, attribute: .left, relatedBy: .equal, toItem: contentView, attribute: .left, multiplier: 1, constant: 0),
76+
])
77+
return cell
78+
}
79+
80+
cells += _cells
81+
// TODO: Improve performance, animated
82+
tableView.reloadData()
83+
}
84+
85+
open func remove(view: UIView, animated: Bool) {
86+
87+
if let index = cells.flatMap({ $0.contentView.subviews.first }).index(of: view) {
88+
cells.remove(at: index)
89+
}
90+
91+
// TODO: Improve performance, animated
92+
tableView.reloadData()
93+
}
94+
95+
public var cells: [UITableViewCell] = []
96+
97+
private let tableView = UITableView(frame: .zero, style: .plain)
98+
99+
// MARK: - UITableViewDataSource
100+
101+
public func numberOfSections(in tableView: UITableView) -> Int {
102+
return 1
103+
}
104+
105+
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
106+
107+
return cells.count
108+
}
109+
110+
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
111+
112+
return cells[indexPath.row]
113+
}
114+
115+
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
116+
117+
let cell = cells[indexPath.row]
118+
119+
let contentView = cell.contentView
120+
let width = NSLayoutConstraint(item: contentView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1, constant: tableView.bounds.width)
121+
122+
NSLayoutConstraint.activate([width])
123+
124+
let size = contentView.systemLayoutSizeFitting(UILayoutFittingCompressedSize)
125+
126+
NSLayoutConstraint.deactivate([width])
127+
128+
return size.height
129+
}
130+
}

0 commit comments

Comments
 (0)