Compare commits

...
13 Commits
Author SHA1 Message Date
Alex.k 656aa95fea Fixes #12 2016-06-06 16:30:37 +03:00
Alex.k 0f00fde7e6 update podspec 2016-06-06 09:38:56 +03:00
Alex f9654a5358 Merge pull request #11 from patrickreynolds/fix/clean-up
Minor cleanup and refactors
2016-06-06 06:33:17 +00:00
Alex dd43c0251f Merge pull request #10 from Dershowitz011/master
Fixes the error of Type 'UIImage' has no member 'Asset' in DemoTableViewController.
2016-06-06 06:30:38 +00:00
Patrick Reynolds b3f881281e Minor clean up and refactors 2016-06-05 19:19:43 -07:00
Shantanu R Desai c17d24bcee Fixes the error of Type 'UIImage' has no member 'Asset' in DemoTableViewController 2016-06-05 00:37:21 +05:30
Alex b1853f8e2a Update README.md 2016-06-02 16:34:25 +03:00
Alex.k 58e672ef87 update podspec 2016-06-02 14:41:54 +03:00
Alex.k de040b348b update readme 2016-06-02 14:40:51 +03:00
Alex.k 01bd7502ca Merge branch 'master' of https://github.com/Ramotion/expanding-collection 2016-06-02 14:40:09 +03:00
Alex.k 8b09ecc842 update readme 2016-06-02 14:40:01 +03:00
Alex 6738ca13cb Update README.md 2016-06-02 12:51:49 +03:00
Alex 19ba6c05aa Update README.md 2016-06-02 12:51:12 +03:00
13 changed files with 75 additions and 70 deletions
@@ -55,4 +55,4 @@ extension AppDelegate {
NSShadowAttributeName: shadow
]
}
}
}
@@ -1,34 +1,33 @@
// Generated using SwiftGen, by O.Halligon — https://github.com/AliSoftware/SwiftGen
import Foundation
import UIKit
import UIKit.UIImage
enum Asset: String {
case BackgroundImage = "BackgroundImage"
case CloseButton = "CloseButton"
case Dots = "dots"
case Face1 = "face1"
case Face2 = "face2"
case Heand = "heand"
case Icons = "icons"
case Image = "image"
case Item0 = "item0"
case Item1 = "item1"
case Item2 = "item2"
case Item3 = "item3"
case LocationButton = "locationButton"
case Map = "map"
case PinIcon = "pinIcon"
case SearchIcon = "searchIcon"
case Stars = "stars"
case Title = "Title"
var image: UIImage {
return UIImage(asset: self)
}
}
extension UIImage {
enum Asset: String {
case BackgroundImage = "BackgroundImage"
case CloseButton = "CloseButton"
case Dots = "dots"
case Face1 = "face1"
case Face2 = "face2"
case Heand = "heand"
case Icons = "icons"
case Image = "image"
case Item0 = "item0"
case Item1 = "item1"
case Item2 = "item2"
case Item3 = "item3"
case LocationButton = "locationButton"
case Map = "map"
case PinIcon = "pinIcon"
case SearchIcon = "searchIcon"
case Stars = "stars"
case Title = "Title"
var image: UIImage {
return UIImage(asset: self)
}
}
convenience init!(asset: Asset) {
self.init(named: asset.rawValue)
}
@@ -9,8 +9,9 @@
import UIKit
extension UICollectionView {
func getReusableCellWithIdentifier<T: UICollectionViewCell where T: CollectionViewCellIdentifiable>(indexPath: NSIndexPath) -> T {
guard let cell = self.dequeueReusableCellWithReuseIdentifier(T.cellIdentifier, forIndexPath: indexPath) as? T else {
guard let cell = dequeueReusableCellWithReuseIdentifier(T.cellIdentifier, forIndexPath: indexPath) as? T else {
fatalError("Couldn't instantiate view controller with identifier \(T.cellIdentifier) ")
}
@@ -23,7 +23,7 @@ extension UIStoryboard {
}
func instantiateViewController<T: UIViewController where T: StoryboardIdentifiable>() -> T {
guard let viewController = self.instantiateViewControllerWithIdentifier(T.storyboardIdentifier) as? T else {
guard let viewController = instantiateViewControllerWithIdentifier(T.storyboardIdentifier) as? T else {
fatalError("Couldn't instantiate view controller with identifier \(T.storyboardIdentifier) ")
}
@@ -14,7 +14,8 @@ class DemoTableViewController: ExpandingTableViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureNavBar()
tableView.backgroundView = UIImageView(image: UIImage.Asset.BackgroundImage.image)
let image1 = Asset.BackgroundImage.image
tableView.backgroundView = UIImageView(image: image1)
}
}
// MARK: Helpers
@@ -33,8 +34,10 @@ extension DemoTableViewController {
@IBAction func backButtonHandler(sender: AnyObject) {
// buttonAnimation
for case let viewController as DemoViewController in navigationController!.viewControllers {
if case let rightButton as AnimatingBarButton = viewController.navigationItem.rightBarButtonItem {
let viewControllers: [DemoViewController?] = navigationController?.viewControllers.map { $0 as? DemoViewController } ?? []
for viewController in viewControllers {
if let rightButton = viewController?.navigationItem.rightBarButtonItem as? AnimatingBarButton {
rightButton.animationSelected(false)
}
}
@@ -49,8 +52,10 @@ extension DemoTableViewController {
override func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentOffset.y < -25 {
// buttonAnimation
for case let viewController as DemoViewController in navigationController!.viewControllers {
if case let rightButton as AnimatingBarButton = viewController.navigationItem.rightBarButtonItem {
let viewControllers: [DemoViewController?] = navigationController?.viewControllers.map { $0 as? DemoViewController } ?? []
for viewController in viewControllers {
if let rightButton = viewController?.navigationItem.rightBarButtonItem as? AnimatingBarButton {
rightButton.animationSelected(false)
}
}
@@ -59,4 +64,4 @@ extension DemoTableViewController {
scrollOffsetY = scrollView.contentOffset.y
}
}
}
@@ -19,6 +19,5 @@ class DemoCollectionViewCell: BasePageCollectionCell {
customTitle.layer.shadowRadius = 2
customTitle.layer.shadowOffset = CGSize(width: 0, height: 3)
customTitle.layer.shadowOpacity = 0.2
}
}
}
@@ -41,7 +41,7 @@ extension DemoViewController {
}
private func fillCellIsOpeenArry() {
for _ in 0..<items.count {
for _ in items {
cellsIsOpen.append(false)
}
}
@@ -75,15 +75,13 @@ extension DemoViewController {
func swipeHandler(sender: UISwipeGestureRecognizer) {
let indexPath = NSIndexPath(forRow: currentIndex, inSection: 0)
guard case let cell as DemoCollectionViewCell = collectionView?.cellForItemAtIndexPath(indexPath) else {
return
}
guard let cell = collectionView?.cellForItemAtIndexPath(indexPath) as? DemoCollectionViewCell else { return }
// double swipe Up transition
if cell.isOpened == true && sender.direction == .Up {
pushToViewController(getViewController())
if case let rightButton as AnimatingBarButton = navigationItem.rightBarButtonItem {
if let rightButton = navigationItem.rightBarButtonItem as? AnimatingBarButton {
rightButton.animationSelected(true)
}
}
@@ -108,9 +106,8 @@ extension DemoViewController {
extension DemoViewController {
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
guard case let cell as DemoCollectionViewCell = cell else {
return
}
guard let cell = cell as? DemoCollectionViewCell else { return }
let index = indexPath.row % 4
let info = items[index]
cell.backgroundImageView?.image = UIImage(named: info.imageName)
@@ -119,17 +116,15 @@ extension DemoViewController {
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
guard case let cell as DemoCollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath) else {
return
}
if currentIndex != indexPath.row { return }
guard let cell = collectionView.cellForItemAtIndexPath(indexPath) as? DemoCollectionViewCell
where currentIndex == indexPath.row else { return }
if cell.isOpened == false {
cell.cellIsOpen(true)
} else {
pushToViewController(getViewController())
if case let rightButton as AnimatingBarButton = navigationItem.rightBarButtonItem {
if let rightButton = navigationItem.rightBarButtonItem as? AnimatingBarButton {
rightButton.animationSelected(true)
}
}
@@ -148,4 +143,3 @@ extension DemoViewController {
return collectionView.dequeueReusableCellWithReuseIdentifier(String(DemoCollectionViewCell), forIndexPath: indexPath)
}
}
@@ -58,10 +58,8 @@ extension AnimatingBarButton {
}
private func configureImageView(imageView: UIImageView, imageName: String) {
guard let customView = self.customView else {
return
}
guard let customView = customView else { return }
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.image = UIImage(named: imageName)
imageView.contentMode = .ScaleAspectFit
@@ -85,5 +83,4 @@ extension AnimatingBarButton {
}
}
}
}
@@ -9,12 +9,12 @@
import UIKit
protocol Rotatable {
func rotateAnimationFrom(fromItem: UIView, toItem: UIView, duration: Double)
}
extension Rotatable {
func rotateAnimationFrom(fromItem: UIView, toItem: UIView, duration: Double) {
let fromRotate = animationFrom(0, to: M_PI, key: "transform.rotation", duration: duration)
@@ -36,7 +36,7 @@ extension Rotatable {
$0.fromValue = from
$0.toValue = to
$0.fillMode = kCAFillModeForwards
$0.removedOnCompletion = false;
$0.removedOnCompletion = false
}
}
}
}
@@ -28,9 +28,8 @@ class DemoExpandingCollectionTests: XCTestCase {
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
measureBlock {
// Put the code you want to measure the time of here.
}
}
}
+9 -3
View File
@@ -5,6 +5,7 @@
[![Twitter](https://img.shields.io/badge/Twitter-@Ramotion-blue.svg?style=flat)](http://twitter.com/Ramotion)
[![CocoaPods](https://img.shields.io/cocoapods/p/expanding-collection.svg)](https://cocoapods.org/pods/expanding-collection)
[![CocoaPods](https://img.shields.io/cocoapods/v/expanding-collection.svg)](http://cocoapods.org/pods/expanding-collection)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Ramotion/expanding-collection)
[![Travis](https://travis-ci.org/Ramotion/elastic-pull-to-update.svg?branch=master)](https://travis-ci.org/Ramotion/elastic-pull-to-update)
[![codebeat badge](https://codebeat.co/badges/6a009992-5bf2-4730-aa35-f3b20ce7693d)](https://codebeat.co/projects/github-com-ramotion-expanding-collection)
@@ -24,8 +25,13 @@ Just add the Source folder to your project.
or use [CocoaPods](https://cocoapods.org) with Podfile:
``` ruby
pod 'expanding-collection', '~> 0.0.2'
pod 'expanding-collection'
```
or [Carthage](https://github.com/Carthage/Carthage) users can simply add to their `Cartfile`:
```
github "Ramotion/expanding-collection"
```
## Usage
```swift
@@ -64,8 +70,8 @@ override func viewDidLoad() {
super.viewDidLoad()
// register cell
let nib = UINib(nibName: "CellIdentifier", bundle: nil)
collectionView?.registerNib(nib, forCellWithReuseIdentifier: String(DemoCollectionViewCell))
let nib = UINib(nibName: "NibName", bundle: nil)
collectionView?.registerNib(nib, forCellWithReuseIdentifier: "CellIdentifier")
}
```
@@ -17,8 +17,13 @@ public class ExpandingViewController: UIViewController {
public var currentIndex: Int {
guard let collectionView = self.collectionView else { return 0 }
let startOffset = (collectionView.bounds.size.width - itemSize.width) / 2
return Int((collectionView.contentOffset.x + startOffset) / (itemSize.width + 25))
let startOffset = (collectionView.bounds.size.width - itemSize.width) / 2
guard let collectionLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else {
return 0
}
let minimumLineSpacing = collectionLayout.minimumLineSpacing
return Int((collectionView.contentOffset.x + startOffset + itemSize.width / 2) / (itemSize.width + minimumLineSpacing))
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'expanding-collection'
s.version = '0.0.2'
s.version = '0.0.5'
s.summary = 'Transition animtion from CollectionView to TableView'
s.license = 'MIT'
s.homepage = 'https://github.com/Ramotion/expanding-collection'