Skip to content

Commit 9e513b3

Browse files
authored
Support horizontal scrolling #15
1 parent af67aa9 commit 9e513b3

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

Podfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
PODS:
2-
- EasyPeasy (1.8.0)
3-
- Reveal-SDK (21)
2+
- EasyPeasy (1.10.0)
3+
- Reveal-SDK (32)
44

55
DEPENDENCIES:
66
- EasyPeasy
77
- Reveal-SDK
88

99
SPEC REPOS:
10-
https://github.com/cocoapods/specs.git:
10+
trunk:
1111
- EasyPeasy
1212
- Reveal-SDK
1313

1414
SPEC CHECKSUMS:
15-
EasyPeasy: bfffe5d47bbaaef3e32888c250a196768484b43a
16-
Reveal-SDK: 3523e0eb7c562811c51bb71da6e523a6373702c8
15+
EasyPeasy: b9b1bae024d21a7dfa9bad26d6826d88348cc6f1
16+
Reveal-SDK: 559f22118e742b3e7d03cd50350efe21a0d0b3ba
1717

1818
PODFILE CHECKSUM: 801a5623355ad33f423fde4c805d2477d85eadb4
1919

20-
COCOAPODS: 1.6.0
20+
COCOAPODS: 1.11.2

StackScrollView.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,12 @@
321321
inputPaths = (
322322
"${PODS_ROOT}/Target Support Files/Pods-StackScrollView-Demo/Pods-StackScrollView-Demo-frameworks.sh",
323323
"${BUILT_PRODUCTS_DIR}/EasyPeasy/EasyPeasy.framework",
324+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Reveal-SDK/RevealServer.framework/RevealServer",
324325
);
325326
name = "[CP] Embed Pods Frameworks";
326327
outputPaths = (
327328
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/EasyPeasy.framework",
329+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RevealServer.framework",
328330
);
329331
runOnlyForDeploymentPostprocessing = 0;
330332
shellPath = /bin/sh;

StackScrollView/StackCell.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
//
2-
// StackCell.swift
3-
// StackScrollView
4-
//
5-
// Created by muukii on 5/2/17.
6-
// Copyright © 2017 muukii. All rights reserved.
7-
//
81

92
import Foundation
3+
import UIKit
104

11-
// MARK: Beta
125
open class StackCell: UIView, StackCellType {
136

147
open var shouldAnimateLayoutChanges: Bool = true

StackScrollView/StackCellType.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import UIKit
2424

25-
public protocol StackCellType : class {
25+
public protocol StackCellType : AnyObject {
2626

2727
}
2828

@@ -45,7 +45,7 @@ extension StackCellType where Self : UIView {
4545

4646
public func scrollToSelf(animated: Bool) {
4747

48-
stackScrollView?.scroll(to: self, animated: animated)
48+
stackScrollView?.scroll(to: self, at: .centeredVertically, animated: animated)
4949
}
5050

5151
public func scrollToSelf(at position: UICollectionView.ScrollPosition, animated: Bool) {

StackScrollView/StackScrollView.swift

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
3030
static let left = "me.muukii.StackScrollView.left"
3131
static let bottom = "me.muukii.StackScrollView.bottom"
3232
static let width = "me.muukii.StackScrollView.width"
33+
static let height = "me.muukii.StackScrollView.height"
3334
}
3435

3536
private static func defaultLayout() -> UICollectionViewFlowLayout {
@@ -51,6 +52,10 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
5152
didSet {
5253
}
5354
}
55+
56+
private var direction: UICollectionView.ScrollDirection {
57+
(collectionViewLayout as! UICollectionViewFlowLayout).scrollDirection
58+
}
5459

5560
// MARK: - Initializers
5661

@@ -323,27 +328,61 @@ open class StackScrollView: UICollectionView, UICollectionViewDataSource, UIColl
323328

324329
if let view = view as? ManualLayoutStackCellType {
325330

326-
return view.size(maxWidth: collectionView.bounds.width, maxHeight: nil)
331+
switch direction {
332+
case .vertical:
333+
return view.size(maxWidth: collectionView.bounds.width, maxHeight: nil)
334+
case .horizontal:
335+
return view.size(maxWidth: nil, maxHeight: collectionView.bounds.height)
336+
@unknown default:
337+
fatalError()
338+
}
327339

328340
} else {
329341

330-
let width: NSLayoutConstraint = {
342+
switch direction {
343+
case .vertical:
331344

332-
guard let c = view.constraints.filter({ $0.identifier == LayoutKeys.width }).first else {
333-
let width = view.widthAnchor.constraint(equalToConstant: collectionView.bounds.width)
334-
width.identifier = LayoutKeys.width
335-
width.isActive = true
336-
return width
337-
}
345+
let width: NSLayoutConstraint = {
338346

339-
return c
340-
}()
347+
guard let c = view.constraints.first(where: { $0.identifier == LayoutKeys.width }) else {
348+
let width = view.widthAnchor.constraint(equalToConstant: collectionView.bounds.width)
349+
width.identifier = LayoutKeys.width
350+
width.isActive = true
351+
return width
352+
}
341353

342-
width.constant = collectionView.bounds.width
354+
return c
355+
}()
343356

344-
let size = view.superview?.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) ?? view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
345-
346-
return size
357+
width.constant = collectionView.bounds.width
358+
359+
let size = view.superview?.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) ?? view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
360+
361+
return size
362+
363+
case .horizontal:
364+
365+
let heightConstraint: NSLayoutConstraint = {
366+
367+
guard let c = view.constraints.first(where: { $0.identifier == LayoutKeys.height }) else {
368+
let heightConstraint = view.heightAnchor.constraint(equalToConstant: collectionView.bounds.height)
369+
heightConstraint.identifier = LayoutKeys.height
370+
heightConstraint.isActive = true
371+
return heightConstraint
372+
}
373+
374+
return c
375+
}()
376+
377+
heightConstraint.constant = collectionView.bounds.width
378+
379+
let size = view.superview?.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) ?? view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
380+
381+
return size
382+
383+
@unknown default:
384+
fatalError()
385+
}
347386

348387
}
349388
}

0 commit comments

Comments
 (0)