Skip to content

Commit

Permalink
Updated the example to enable toggling between scrolling direction.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinJin committed Feb 22, 2017
1 parent d539aee commit 02799a2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
3 changes: 3 additions & 0 deletions iOS Example/Source/AnimatorTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ class AnimatorTableViewController: UITableViewController {
(TurnAttributeAnimator(), true),
(PageAttributeAnimator(), true)]

@IBOutlet weak var isHorizontalScrollToggle: UISwitch!

override func viewDidLoad() {
super.viewDidLoad()
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let dist = segue.destination as? ImageCollectionViewController, let indexPath = sender as? IndexPath {
dist.animator = animators[indexPath.row]
dist.direction = isHorizontalScrollToggle.isOn ? .horizontal : .vertical
}
}

Expand Down
21 changes: 12 additions & 9 deletions iOS Example/Source/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
<rect key="frame" x="0.0" y="0.0" width="200" height="200"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="rEp-7G-ele">
<rect key="frame" x="0.0" y="0.0" width="200" height="200"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QSQ-Xq-WAm">
<rect key="frame" x="-9" y="39" width="218.5" height="123"/>
<fontDescription key="fontDescription" name="AvenirNext-UltraLight" family="Avenir Next" pointSize="90"/>
Expand All @@ -45,15 +42,10 @@
</view>
<constraints>
<constraint firstItem="QSQ-Xq-WAm" firstAttribute="centerX" secondItem="PaF-XJ-Xcy" secondAttribute="centerX" id="9ef-xY-PkK"/>
<constraint firstItem="rEp-7G-ele" firstAttribute="height" secondItem="PaF-XJ-Xcy" secondAttribute="height" id="A8q-In-0iS"/>
<constraint firstItem="QSQ-Xq-WAm" firstAttribute="centerY" secondItem="PaF-XJ-Xcy" secondAttribute="centerY" id="Ka3-TZ-Uga"/>
<constraint firstItem="rEp-7G-ele" firstAttribute="width" secondItem="PaF-XJ-Xcy" secondAttribute="width" id="VWm-DV-EL2"/>
<constraint firstItem="rEp-7G-ele" firstAttribute="centerY" secondItem="PaF-XJ-Xcy" secondAttribute="centerY" id="pAQ-sA-XXz"/>
<constraint firstItem="rEp-7G-ele" firstAttribute="centerX" secondItem="PaF-XJ-Xcy" secondAttribute="centerX" id="yZz-3A-8OJ"/>
</constraints>
<size key="customSize" width="200" height="200"/>
<connections>
<outlet property="imageView" destination="rEp-7G-ele" id="c00-fB-pdC"/>
<outlet property="titleLabel" destination="QSQ-Xq-WAm" id="8Vm-ea-2IG"/>
</connections>
</collectionViewCell>
Expand All @@ -64,6 +56,9 @@
<outletCollection property="gestureRecognizers" destination="fV7-M7-lkK" appends="YES" id="xdo-8N-nFh"/>
</connections>
</collectionView>
<connections>
<outlet property="dismissGesture" destination="fV7-M7-lkK" id="f4D-o0-056"/>
</connections>
</collectionViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Q7N-eU-rZ2" userLabel="First Responder" sceneMemberID="firstResponder"/>
<swipeGestureRecognizer direction="down" id="fV7-M7-lkK">
Expand All @@ -87,8 +82,16 @@
<outlet property="delegate" destination="1N0-Hp-srR" id="mtz-Pt-omi"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="cZr-2G-mbD"/>
<navigationItem key="navigationItem" id="cZr-2G-mbD">
<barButtonItem key="rightBarButtonItem" title="Horizontal Scroll" style="plain" id="fms-Ek-KSO">
<switch key="customView" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="zF8-Bv-g8k">
<rect key="frame" x="310" y="6" width="51" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="isHorizontalScrollToggle" destination="zF8-Bv-g8k" id="B4Q-KV-sq9"/>
<segue destination="24e-mu-gTV" kind="presentation" identifier="ShowCollectionViewController" id="eY7-aQ-bXf"/>
</connections>
</tableViewController>
Expand Down
15 changes: 12 additions & 3 deletions iOS Example/Source/ImageCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import AnimatedCollectionViewLayout

class SimpleCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!

func bind(color: String, imageName: String) {
titleLabel.text = "\(arc4random_uniform(1000))"
override func awakeFromNib() {
super.awakeFromNib()
backgroundColor = .clear
}

func bind(color: String, imageName: String) {
contentView.backgroundColor = color.hexColor
titleLabel.text = "\(arc4random_uniform(1000))"
}
}

Expand All @@ -43,7 +46,10 @@ extension String {

class ImageCollectionViewController: UICollectionViewController {

@IBOutlet var dismissGesture: UISwipeGestureRecognizer!

var animator: (LayoutAttributesAnimator, Bool)?
var direction: UICollectionViewScrollDirection = .horizontal

let cellIdentifier = "SimpleCollectionViewCell"
let vcs = [("f44336", "nature1"),
Expand All @@ -61,8 +67,11 @@ class ImageCollectionViewController: UICollectionViewController {
collectionView?.isPagingEnabled = true

if let layout = collectionView?.collectionViewLayout as? AnimatedCollectionViewLayout {
layout.scrollDirection = direction
layout.animator = animator?.0
}

dismissGesture.direction = direction == .horizontal ? .down : .left
}

override func didReceiveMemoryWarning() {
Expand Down

0 comments on commit 02799a2

Please sign in to comment.