Compare commits

...
8 Commits
Author SHA1 Message Date
Alex.k fdea171402 Fixes #18 2016-06-08 16:22:41 +03:00
Alex.k 956a270b1e update podspec 2016-06-08 14:42:29 +03:00
Alex.k b832f9e372 Fixes #17 2016-06-08 14:40:44 +03:00
Alex aa66607cbd Merge pull request #15 from Dershowitz011/master
Readme fixed again.. -_-
2016-06-07 13:38:40 +00:00
Alex.k 2ef07885b7 update podspec 2016-06-07 16:31:37 +03:00
Alex.k d89e99654f Fixes #14 2016-06-07 16:29:44 +03:00
Shantanu R Desai c91a711dd8 Readme fixed again.. -_- 2016-06-07 17:51:18 +05:30
Alex.k a003cc01d1 update readme 2016-06-07 11:37:26 +03:00
9 changed files with 97 additions and 31 deletions
@@ -49,7 +49,6 @@ extension AppDelegate {
shadow.shadowOffset = CGSize(width: 0, height: 2)
shadow.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1)
// shadow.shadowOffset = k
UINavigationBar.appearance().titleTextAttributes = [
NSForegroundColorAttributeName : UIColor.whiteColor(),
NSShadowAttributeName: shadow
@@ -50,17 +50,17 @@ extension DemoTableViewController {
extension DemoTableViewController {
override func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.contentOffset.y < -25 {
// buttonAnimation
let viewControllers: [DemoViewController?] = navigationController?.viewControllers.map { $0 as? DemoViewController } ?? []
for viewController in viewControllers {
if let rightButton = viewController?.navigationItem.rightBarButtonItem as? AnimatingBarButton {
rightButton.animationSelected(false)
}
}
popTransitionAnimation()
}
// if scrollView.contentOffset.y < -25 {
// // buttonAnimation
// let viewControllers: [DemoViewController?] = navigationController?.viewControllers.map { $0 as? DemoViewController } ?? []
//
// for viewController in viewControllers {
// if let rightButton = viewController?.navigationItem.rightBarButtonItem as? AnimatingBarButton {
// rightButton.animationSelected(false)
// }
// }
// popTransitionAnimation()
// }
scrollOffsetY = scrollView.contentOffset.y
}
@@ -22,6 +22,7 @@ class DemoViewController: ExpandingViewController {
extension DemoViewController {
override func viewDidLoad() {
itemSize = CGSize(width: 256, height: 335)
super.viewDidLoad()
registerCell()
@@ -104,7 +105,8 @@ extension DemoViewController {
extension DemoViewController {
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
override func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
super.collectionView(collectionView, willDisplayCell: cell, forItemAtIndexPath: indexPath)
guard let cell = cell as? DemoCollectionViewCell else { return }
let index = indexPath.row % items.count
+4 -2
View File
@@ -5,6 +5,8 @@
[![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)
[![CocoaPods](https://img.shields.io/cocoapods/metrics/doc-percent/expanding-collection.svg)](https://cdn.rawgit.com/Ramotion/expanding-collection/master/docs/index.html)
[![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)
@@ -25,7 +27,7 @@ Just add the Source folder to your project.
or use [CocoaPods](https://cocoapods.org) with Podfile:
``` ruby
pod 'expanding-collection'
pod 'expanding-collection'
```
or [Carthage](https://github.com/Carthage/Carthage) users can simply add to their `Cartfile`:
```
@@ -35,7 +37,7 @@ github "Ramotion/expanding-collection"
## Usage
```swift
import expanding_collection
import ExpandingCollection
```
#### Create CollectionViewCell
@@ -24,10 +24,22 @@ extension ExpandingTableViewController {
private func getScreen() -> UIImage? {
let height = (headerHeight - tableView.contentOffset.y) < 0 ? 0 : (headerHeight - tableView.contentOffset.y)
let backImageSize = CGSize(width: view.bounds.width, height: view.bounds.height - height)
let backImageSize = CGSize(width: view.bounds.width, height: view.bounds.height - height + getTabBarHeight())
let backImageOrigin = CGPoint(x: 0, y: height + tableView.contentOffset.y)
return view.takeSnapshot(CGRect(origin: backImageOrigin, size: backImageSize))
}
private func getTabBarHeight() -> CGFloat {
guard let navigationController = self.navigationController else {
return 0
}
let insets = automaticallyAdjustsScrollViewInsets
let tabBarHeight = insets == true ? navigationController.navigationBar.frame.size.height : 0
let stausBarHeight = insets == true ? UIApplication.sharedApplication().statusBarFrame.size.height : 0
return tabBarHeight + stausBarHeight
}
}
// MARK: Methods
@@ -43,7 +55,10 @@ extension ExpandingTableViewController {
}
let backImage = getScreen()
let offset = tableView.contentOffset.y > headerHeight ? headerHeight : tableView.contentOffset.y
var offset = tableView.contentOffset.y > headerHeight ? headerHeight : tableView.contentOffset.y
offset += getTabBarHeight()
transitionDriver.popTransitionAnimationContantOffset(offset, backImage: backImage)
self.navigationController?.popViewControllerAnimated(false)
}
@@ -101,17 +101,20 @@ extension BasePageCollectionCell {
public func cellIsOpen(isOpen: Bool, animated: Bool = true) {
if isOpen == isOpened { return }
frontConstraintY.constant = isOpen == true ? -bounds.size.height / 5 : 0
backConstraintY.constant = isOpen == true ? bounds.size.height / 5 - yOffset / 2 : 0
frontConstraintY.constant = isOpen == true ? -frontContainerView.bounds.size.height / 5 : 0
backConstraintY.constant = isOpen == true ? frontContainerView.bounds.size.height / 5 - yOffset / 2 : 0
if let widthConstant = backContainerView.getConstraint(.Width) {
widthConstant.constant = isOpen == true ? contentView.bounds.size.width + yOffset : contentView.bounds.size.width
widthConstant.constant = isOpen == true ? frontContainerView.bounds.size.width + yOffset : frontContainerView.bounds.size.width
}
if let heightConstant = backContainerView.getConstraint(.Height) {
heightConstant.constant = isOpen == true ? contentView.bounds.size.height + yOffset : contentView.bounds.size.height
heightConstant.constant = isOpen == true ? frontContainerView.bounds.size.height + yOffset : frontContainerView.bounds.size.height
}
configurationCell()
if animated == true {
UIView.animateWithDuration(0.3, delay: 0, options: .CurveEaseInOut, animations: {
self.contentView.layoutIfNeeded()
@@ -178,6 +181,26 @@ extension BasePageCollectionCell {
return shadow
}
func configurationCell() {
frame.size.height += (superview?.frame.size.height)!
frame.origin.y -= (superview?.frame.size.height)! / 2
frame.origin.x -= yOffset / 2
frame.size.width += yOffset
}
func configureCellViewConstraintsWithSize(size: CGSize) {
guard isOpened == false && frontContainerView.getConstraint(.Width)?.constant != size.width else { return }
[frontContainerView, backContainerView].forEach {
let constraintWidth = $0.getConstraint(.Width)
constraintWidth?.constant = size.width
let constraintHeight = $0.getConstraint(.Height)
constraintHeight?.constant = size.height
}
}
}
// MARK: NSCoding
@@ -53,17 +53,22 @@ public extension ExpandingViewController {
- parameter viewController: The table view controller to push onto the stack.
*/
func pushToViewController(viewController: ExpandingTableViewController) {
guard let collectionView = self.collectionView else {
guard let collectionView = self.collectionView,
let navigationController = self.navigationController else {
return
}
viewController.transitionDriver = transitionDriver
let insets = viewController.automaticallyAdjustsScrollViewInsets
let tabBarHeight = insets == true ? navigationController.navigationBar.frame.size.height : 0
let stausBarHeight = insets == true ? UIApplication.sharedApplication().statusBarFrame.size.height : 0
let backImage = getBackImage(viewController, headerHeight: viewController.headerHeight)
transitionDriver?.pushTransitionAnimationIndex(currentIndex,
collecitionView: collectionView,
backImage: backImage,
headerHeight: viewController.headerHeight) { headerView in
headerHeight: viewController.headerHeight,
insets: tabBarHeight + stausBarHeight) { headerView in
viewController.tableView.tableHeaderView = headerView
self.navigationController?.pushViewController(viewController, animated: false)
}
@@ -100,8 +105,15 @@ extension ExpandingViewController {
// MARK: UICollectionViewDataSource
extension ExpandingViewController: UICollectionViewDataSource, UICollectionViewDelegate{
extension ExpandingViewController: UICollectionViewDataSource, UICollectionViewDelegate {
public func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
guard case let cell as BasePageCollectionCell = cell else {
return
}
cell.configureCellViewConstraintsWithSize(itemSize)
}
public func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
fatalError("need emplementation in subclass")
}
@@ -111,3 +123,15 @@ extension ExpandingViewController: UICollectionViewDataSource, UICollectionViewD
}
}
// MARK: UIScrollViewDelegate
extension ExpandingViewController {
public func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
let indexPath = NSIndexPath(forRow: currentIndex, inSection: 0)
if case let currentCell as BasePageCollectionCell = collectionView?.cellForItemAtIndexPath(indexPath) {
currentCell.configurationCell()
}
}
}
@@ -45,6 +45,7 @@ extension TransitionDriver {
collecitionView: UICollectionView,
backImage: UIImage?,
headerHeight: CGFloat,
insets: CGFloat,
completion: UIView -> Void) {
guard case let cell as BasePageCollectionCell = collecitionView.cellForItemAtIndexPath(NSIndexPath(forRow: currentIndex, inSection: 0)),
@@ -60,8 +61,8 @@ extension TransitionDriver {
configurateCell(copyView, backImage: backImage)
backImageView = addImageToView(copyView.backContainerView, image: backImage)
openBackViewConfigureConstraints(copyView, height: headerHeight)
openFrontViewConfigureConstraints(copyView, height: headerHeight)
openBackViewConfigureConstraints(copyView, height: headerHeight, insets: insets)
openFrontViewConfigureConstraints(copyView, height: headerHeight, insets: insets)
// corner animation
copyView.backContainerView.animationCornerRadius(0, duration: duration)
@@ -188,7 +189,7 @@ extension TransitionDriver {
extension TransitionDriver {
private func openFrontViewConfigureConstraints(cell: BasePageCollectionCell, height: CGFloat) {
private func openFrontViewConfigureConstraints(cell: BasePageCollectionCell, height: CGFloat, insets: CGFloat) {
if let heightConstraint = cell.frontContainerView.getConstraint(.Height) {
frontViewFrame.size.height = heightConstraint.constant
@@ -201,10 +202,10 @@ extension TransitionDriver {
}
frontViewFrame.origin.y = cell.frontConstraintY.constant
cell.frontConstraintY.constant = -view.bounds.size.height / 2 + height / 2
cell.frontConstraintY.constant = -view.bounds.size.height / 2 + height / 2 + insets
}
private func openBackViewConfigureConstraints(cell: BasePageCollectionCell, height: CGFloat) {
private func openBackViewConfigureConstraints(cell: BasePageCollectionCell, height: CGFloat, insets: CGFloat) {
if let heightConstraint = cell.backContainerView.getConstraint(.Height) {
backViewFrame.size.height = heightConstraint.constant
@@ -217,7 +218,7 @@ extension TransitionDriver {
}
backViewFrame.origin.y = cell.backConstraintY.constant
cell.backConstraintY.constant = view.bounds.size.height / 2 - (view.bounds.size.height - 236) / 2
cell.backConstraintY.constant = view.bounds.size.height / 2 - (view.bounds.size.height - 236) / 2 + insets
}
private func closeBackViewConfigurationConstraints(cell: BasePageCollectionCell?) {
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'expanding-collection'
s.version = '0.0.6'
s.version = '0.2.1'
s.summary = 'Transition animtion from CollectionView to TableView'
s.license = 'MIT'
s.homepage = 'https://github.com/Ramotion/expanding-collection'