Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add several other actions
  • Loading branch information
malcommac committed Oct 5, 2019
1 parent 52df620 commit 5dbddb6
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 17 deletions.
Binary file not shown.
95 changes: 92 additions & 3 deletions ScrollStackControllerDemo/Base.lproj/Main.storyboard
Expand Up @@ -21,28 +21,117 @@
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="a7Q-tz-rI1">
<rect key="frame" x="20" y="64" width="153" height="30"/>
<rect key="frame" x="20" y="64" width="100" height="30"/>
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="153" id="eZt-64-3CB"/>
<constraint firstAttribute="width" constant="100" id="eZt-64-3CB"/>
<constraint firstAttribute="height" constant="30" id="uxI-ig-f5J"/>
</constraints>
<state key="normal" title="Add Random Row">
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<state key="normal" title="Add Row">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="addNewRow" destination="BYZ-38-t0r" eventType="touchUpInside" id="O6D-J0-3dz"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ljg-R8-0k8">
<rect key="frame" x="128" y="64" width="100" height="30"/>
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="huO-0H-rxs"/>
<constraint firstAttribute="height" constant="30" id="tRQ-JP-7ZS"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<state key="normal" title="Hide/Show Row">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="hideOrShowRandomRow" destination="BYZ-38-t0r" eventType="touchUpInside" id="RIt-EZ-Kgx"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="a8U-7G-txi">
<rect key="frame" x="234" y="64" width="100" height="30"/>
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="HwD-9V-Np7"/>
<constraint firstAttribute="height" constant="30" id="z3X-Ls-g0O"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<state key="normal" title="Toggle Axis">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="toggleAxis" destination="BYZ-38-t0r" eventType="touchUpInside" id="lTz-Zf-aGb"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1E4-jE-O3H">
<rect key="frame" x="20" y="102" width="100" height="30"/>
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="rPh-35-aIt"/>
<constraint firstAttribute="height" constant="30" id="stZ-Fb-Grb"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<state key="normal" title="Remove Row">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="removeRow" destination="BYZ-38-t0r" eventType="touchUpInside" id="Ew3-2d-JtQ"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fOH-Lh-1KN">
<rect key="frame" x="128" y="102" width="100" height="30"/>
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="120" id="cCH-ma-tnV"/>
<constraint firstAttribute="height" constant="30" id="cEJ-WA-VDZ"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<state key="normal" title="Move Row">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="moveRowToRandom" destination="BYZ-38-t0r" eventType="touchUpInside" id="Idy-re-ZnJ"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RgW-dD-Pae">
<rect key="frame" x="236" y="102" width="100" height="30"/>
<color key="backgroundColor" red="0.1333333333" green="0.31372549020000001" blue="0.4039215686" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="OkB-g1-BxM"/>
<constraint firstAttribute="height" constant="30" id="Yvg-In-cn5"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<state key="normal" title="Scroll Random">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="scrollToRandom" destination="BYZ-38-t0r" eventType="touchUpInside" id="MCK-YZ-Rfh"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="O4f-A9-7JM" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="100" id="0Rg-6l-Mie"/>
<constraint firstItem="1E4-jE-O3H" firstAttribute="top" secondItem="a7Q-tz-rI1" secondAttribute="bottom" constant="8" id="3Oj-iN-93f"/>
<constraint firstItem="1E4-jE-O3H" firstAttribute="leading" secondItem="a7Q-tz-rI1" secondAttribute="leading" id="3Vd-Dh-zJV"/>
<constraint firstItem="a8U-7G-txi" firstAttribute="leading" secondItem="Ljg-R8-0k8" secondAttribute="trailing" constant="6" id="3nd-oJ-x2R"/>
<constraint firstItem="a8U-7G-txi" firstAttribute="centerY" secondItem="Ljg-R8-0k8" secondAttribute="centerY" id="9XS-mQ-jl2"/>
<constraint firstItem="Ljg-R8-0k8" firstAttribute="leading" secondItem="a7Q-tz-rI1" secondAttribute="trailing" constant="8" id="9oc-yh-5NS"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="O4f-A9-7JM" secondAttribute="trailing" constant="20" id="AZR-eI-SfX"/>
<constraint firstItem="a7Q-tz-rI1" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="20" id="QI2-1l-xUr"/>
<constraint firstItem="Ljg-R8-0k8" firstAttribute="centerY" secondItem="a7Q-tz-rI1" secondAttribute="centerY" id="aAx-iH-qTe"/>
<constraint firstItem="fOH-Lh-1KN" firstAttribute="leading" secondItem="Ljg-R8-0k8" secondAttribute="leading" id="agR-VU-Bya"/>
<constraint firstItem="Ljg-R8-0k8" firstAttribute="height" secondItem="a7Q-tz-rI1" secondAttribute="height" id="cf3-CR-loY"/>
<constraint firstItem="fOH-Lh-1KN" firstAttribute="trailing" secondItem="Ljg-R8-0k8" secondAttribute="trailing" id="ew0-ea-gOG"/>
<constraint firstItem="a7Q-tz-rI1" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="hNF-QF-Cti"/>
<constraint firstItem="O4f-A9-7JM" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="jiX-gL-rHy"/>
<constraint firstItem="fOH-Lh-1KN" firstAttribute="centerY" secondItem="1E4-jE-O3H" secondAttribute="centerY" id="ma9-he-lTe"/>
<constraint firstItem="1E4-jE-O3H" firstAttribute="trailing" secondItem="a7Q-tz-rI1" secondAttribute="trailing" id="ndi-rV-8Yu"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="O4f-A9-7JM" secondAttribute="bottom" constant="20" id="pEb-ou-B47"/>
<constraint firstItem="RgW-dD-Pae" firstAttribute="centerY" secondItem="fOH-Lh-1KN" secondAttribute="centerY" id="y1e-Cv-LRW"/>
<constraint firstItem="RgW-dD-Pae" firstAttribute="leading" secondItem="fOH-Lh-1KN" secondAttribute="trailing" constant="8" id="ysb-Fy-Val"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
Expand Down
39 changes: 26 additions & 13 deletions ScrollStackControllerDemo/ViewController.swift
Expand Up @@ -36,24 +36,37 @@ class ViewController: UIViewController {
tagsVC = TagsVC.create(delegate: self)
stackView.addRow(controller: tagsVC, at: .top, animated: false)
}

@IBAction public func toggleAxis() {

// (stackView.rows[0].controller as! VC1).bestSize = 50
// (stackView.rows[1].controller as! VC1).bestSize = 30
// stackController.stackView.reloadRows(indexes: [0,1], animated: true)


// stackController.stackView.setRowHidden(index: 0, isHidden: true, animated: true)
// stackController.stackView.replaceRowAtIndex(1, withRow: otherVC, animated: true)
// stackController.stackView.moveRowAtIndex(1, to: 2, animated: true)
//stackController.stackView.axis = (stackController.stackView.axis == .horizontal ? .vertical : .horizontal)
}

@IBAction public func addNewRow() {
let galleryVC = GalleryVC.create()
stackView.addRow(controller: galleryVC, at: .bottom, animated: true)
}

@IBAction public func hideOrShowRandomRow() {
let randomRow = Int.random(in: 0..<stackView.rows.count)
let newRowStatus = !stackView.rows[randomRow].isHidden
stackView.setRowHidden(index: randomRow, isHidden: newRowStatus, animated: true)
}

@IBAction public func moveRowToRandom() {
let randomSrc = Int.random(in: 0..<stackView.rows.count)
let randomDst = Int.random(in: 0..<stackView.rows.count)
stackView.moveRow(index: randomSrc, to: randomDst, animated: true, completion: nil)
}

@IBAction public func removeRow() {
let randomRow = Int.random(in: 0..<stackView.rows.count)
stackView.removeRow(index: randomRow, animated: true)
}

@IBAction public func toggleAxis() {
stackView.toggleAxis(animated: true)
}

@IBAction public func scrollToRandom() {
let randomRow = Int.random(in: 0..<stackView.rows.count)
stackView.scrollToRow(index: randomRow, at: .middle, animated: true)
}
}

extension ViewController: TagsVCProtocol {
Expand Down
12 changes: 11 additions & 1 deletion Sources/ScrollStackController/ScrollStack.swift
Expand Up @@ -380,6 +380,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
}
stackView.insertArrangedSubview(sourceRow, at: destIndex)
postInsertRow(sourceRow, animated: false)
stackView.setNeedsLayout()
}

guard animated else {
Expand All @@ -388,7 +389,6 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
return
}

stackView.setNeedsLayout()
UIView.execute(executeMoveRow, completion: completion)
}

Expand Down Expand Up @@ -538,6 +538,16 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
}
}

/// Invert axis of scroll.
///
/// - Parameter animated: `true` to animate operation.
/// - Parameter completion: completion callback.
open func toggleAxis(animated: Bool = false, completion: (() -> Void)? = nil) {
UIView.execute(animated: animated, {
self.axis = (self.axis == .horizontal ? .vertical : .horizontal)
}, completion: completion)
}

// MARK: - Private Functions

/// Initial configuration of the control.
Expand Down

0 comments on commit 5dbddb6

Please sign in to comment.