forked from marcosgriselli/ViewAnimator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds example animation for UICollectionView. marcosgriselli#32
- Loading branch information
1 parent
334ee3d
commit 7fb4da4
Showing
8 changed files
with
251 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Example/ViewAnimator/ViewControllers/CollectionViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// CollectionViewController.swift | ||
// ViewAnimator_Example | ||
// | ||
// Created by Marcos Griselli on 04/02/2018. | ||
// Copyright © 2018 CocoaPods. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import ViewAnimator | ||
|
||
private let reuseIdentifier = "Cell" | ||
|
||
class CollectionViewController: UIViewController { | ||
|
||
private var items = [Any?]() | ||
@IBOutlet weak var collectionView: UICollectionView! | ||
@IBOutlet weak var activityIndicator: UIActivityIndicatorView! | ||
private let animations = [AnimationType.from(direction: .bottom, offset: 30.0)] | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
collectionView.dataSource = self | ||
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) | ||
} | ||
|
||
@IBAction func animateTapped(_ sender: UIBarButtonItem) { | ||
sender.isEnabled = false | ||
activityIndicator.stopAnimating() | ||
items = Array(repeating: nil, count: 20) | ||
collectionView?.reloadData() | ||
collectionView?.performBatchUpdates({ | ||
self.collectionView?.animateViews(animations: animations, | ||
completion: { | ||
sender.isEnabled = true | ||
}) | ||
}, completion: nil) | ||
} | ||
|
||
@IBAction func resetTapped(_ sender: UIBarButtonItem) { | ||
items.removeAll() | ||
collectionView?.animateViews(animations: animations, reversed: true, initialAlpha: 1.0, finalAlpha: 0.0, | ||
completion: { | ||
self.collectionView?.restoreViewsToIdentity() | ||
self.collectionView?.reloadData() | ||
self.activityIndicator.startAnimating() | ||
}) | ||
} | ||
} | ||
|
||
// MARK: UICollectionViewDataSource | ||
extension CollectionViewController: UICollectionViewDataSource { | ||
|
||
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | ||
return items.count | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | ||
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) | ||
cell.contentView.backgroundColor = UIColor.red | ||
return cell | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "fastlane" | ||
gem "cocoapods" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Utilities.swift | ||
// Pods-ViewAnimator_Example | ||
// | ||
// Created by Marcos Griselli on 10/7/17. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - Bool | ||
extension Bool { | ||
|
||
/// Generates a random bool. | ||
/// | ||
/// - Returns: Bool. | ||
static func random() -> Bool { | ||
return arc4random_uniform(2) == 0 | ||
} | ||
} | ||
|
||
// MARK: Double | ||
public extension Double { | ||
|
||
/// Returns a random floating point number between 0.0 and 1.0, inclusive. | ||
public static var random: Double { | ||
return Double(arc4random()) / 0xFFFFFFFF | ||
} | ||
|
||
/// Generates a random double. | ||
/// | ||
/// - Parameters: | ||
/// - min: Minimum value of the random value. | ||
/// - max: Maximum value of the random value. | ||
/// - Returns: Generated value. | ||
public static func random(min: Double, max: Double) -> Double { | ||
return Double.random * (max - min) + min | ||
} | ||
} | ||
|
||
// MARK: Float Extension | ||
|
||
public extension Float { | ||
|
||
/// Returns a random floating point number between 0.0 and 1.0, inclusive. | ||
public static var random: Float { | ||
return Float(arc4random()) / 0xFFFFFFFF | ||
} | ||
} | ||
|
||
extension CGFloat { | ||
|
||
/// Returns a random floating point number between 0.0 and 1.0, inclusive. | ||
public static var random: CGFloat { | ||
return CGFloat(Float.random) | ||
} | ||
|
||
/// Generates a random CGFloat. | ||
/// | ||
/// - Parameters: | ||
/// - min: Minimum value of the random value. | ||
/// - max: Maximum value of the random value. | ||
/// - Returns: Generated value. | ||
public static func random(min: CGFloat, max: CGFloat) -> CGFloat { | ||
return CGFloat.random * (max - min) + min | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ViewAnimator/Classes/Utilities/UIScrollView + isRefreshing.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// UIScrollView + isRefreshing.swift | ||
// ViewAnimator | ||
// | ||
// Created by Marcos Griselli on 1/24/18. | ||
// | ||
|
||
import UIKit | ||
|
||
@available(iOS 10.0, *) | ||
extension UIScrollView { | ||
|
||
var isRefreshControlVisible: Bool { | ||
return refreshControl?.isRefreshing == true | ||
} | ||
} |