Skip to content

Commit

Permalink
Merge 320f77e into a26d4b4
Browse files Browse the repository at this point in the history
  • Loading branch information
Oni-zerone committed Jun 15, 2019
2 parents a26d4b4 + 320f77e commit 28ef880
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Expand Up @@ -5,8 +5,8 @@ PODS:
- PowerTools/CollectionVM (0.3.0):
- PowerTools/Core
- PowerTools/Core (0.3.0)
- SafariLayout (0.1.0)
- StoriesLayout (0.1.0)
- SafariLayout (0.1.1)
- StoriesLayout (0.1.1)

DEPENDENCIES:
- PowerTools (~> 0.3)
Expand All @@ -25,8 +25,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
PowerTools: c8c15dae195d431668aef9feb79b684ea764def9
SafariLayout: 243bc97a21809b13f34e4f1b84f32bd5211593a9
StoriesLayout: 28d3eccd89bd24122f5215d2ec7ebcc259de9e3c
SafariLayout: ead4b2e58882f84b0ebbd32cd3255795277ac744
StoriesLayout: 694a3c67a705dbb8bdd6b4ce7c512fd7389d487c

PODFILE CHECKSUM: d0bf00e63b108958ce7b8b9d96edb753c10b957b

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/StoriesLayout.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -3,6 +3,18 @@
[![codebeat badge](https://codebeat.co/badges/69b7abb0-6470-4247-ab1f-5281e4ca0aa6)](https://codebeat.co/projects/github-com-oni-zerone-collectionlayouts-develop)
[![Coverage Status](https://coveralls.io/repos/github/Oni-zerone/CollectionLayouts/badge.svg?branch=develop)](https://coveralls.io/github/Oni-zerone/CollectionLayouts?branch=develop)

![SafariLayout](http://studiout.it/github/SafariLayout.png)

[![Version](https://img.shields.io/cocoapods/v/StoriesLayout.svg?style=flat)](https://cocoapods.org/pods/SafariLayout)
[![License](https://img.shields.io/cocoapods/l/StoriesLayout.svg?style=flat)](https://cocoapods.org/pods/SafariLayout)
[![Platform](https://img.shields.io/cocoapods/p/StoriesLayout.svg?style=flat)](https://cocoapods.org/pods/SafariLayout)

This is a UICollectionViewLayout that reproduce the iOS Safari tabs experience,
just use SafariCollectionViewLayout in your UICollectionView and subclass your cells from SafariCollectionViewCell!

### Installation
* Via cocoapods: `pod 'SafariLayout'`

![StoriesLayout](http://studiout.it/github/StoriesLayout.png)

[![Version](https://img.shields.io/cocoapods/v/StoriesLayout.svg?style=flat)](https://cocoapods.org/pods/StoriesLayout)
Expand Down
2 changes: 1 addition & 1 deletion SafariLayout.podspec
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SafariLayout'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'A Safari tabs like UICollectionViewLayout'
s.swift_version = '5.0'
s.description = <<-DESC
Expand Down
3 changes: 3 additions & 0 deletions SafariLayout/Classes/SafariCollectionViewCell.swift
Expand Up @@ -7,6 +7,9 @@

import UIKit

/**
SafariCollectionViewCell is a base class that you could use to create your custom cells with the tilted tab experience.
*/
open class SafariCollectionViewCell: UICollectionViewCell {

override open func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
Expand Down
40 changes: 39 additions & 1 deletion SafariLayout/Classes/SafariCollectionViewLayout.swift
Expand Up @@ -7,11 +7,25 @@

import UIKit

/**
A concrete layout object that reproduce the look and feel of the Safari tab bars.
The items will be shown in a single column aligned as cards with the same dimension of the screen tilted in relation to the position in the collection.
Actually there isn't a specific delegate to customize layout behviors of the cells.
*/
@IBDesignable
public class SafariCollectionViewLayout: UICollectionViewLayout {

private var _tabsCount: Int = 4

/**
The maximum number of tabs shown on the screen.
Line spacing between the cells will be calculated based on this parameter.
Default value of this property is 4
*/
@IBInspectable public var tabsCount: Int {
set {
_tabsCount = max(newValue, 1)
Expand All @@ -22,9 +36,33 @@ public class SafariCollectionViewLayout: UICollectionViewLayout {
}
}

/**
The angle that the cell assumes at the center of the collection.
This is the main value used to tune the cell position in the collection.
Define the overall orientation of the cell and the appearance in the collection.
Default value of this property is 114 degrees.
*/
var defaultAngle: CGFloat = CGFloat.pi * 0.2

/**
The angle variation between the top and the center of the collection.
This is the value used to realize the tilting effect when the cell moves in the collection.
Define the overall orientation of the cell and the appearance in the collection.
Default value of this property is 180 degrees.
*/
var variationAngle: CGFloat = CGFloat.pi * 0.2

/**
Defines the contentSize of the collectionView
Actually SafariCollectionViewLayout can handle a single section and the cell size is determined as the same of the collection, but tilted.
Line spacing between the cells is defined by the tabs count.
*/
override public var collectionViewContentSize: CGSize {
guard let collection = collectionView,
let dataSource = collection.dataSource else {
Expand All @@ -43,7 +81,7 @@ public class SafariCollectionViewLayout: UICollectionViewLayout {
return CGSize(width: collection.bounds.width,
height: CGFloat(cellsCount) * (collection.bounds.height / CGFloat(_tabsCount)))
}

override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {

let firstVisibleItem = self.firstVisibleItem
Expand Down
16 changes: 14 additions & 2 deletions SafariLayout/Classes/SafariCollectionViewLayoutAttributes.swift
Expand Up @@ -6,18 +6,30 @@
//

import UIKit

/**
The custom `UICollectionViewLayoutAttributes` subclass used by `SafariCollectionViewLayout`
*/
class SafariCollectionViewLayoutAttributes: UICollectionViewLayoutAttributes {

/**
Anchor point is the realtive position used to calculate the tilt transformation of the cell.
If you won't use the `SafariCollectionViewCell` as your base cell class remember to override
`func apply(_ layoutAttributes: UICollectionViewLayoutAttributes)` method to pass the anchorPoint property
to the cell layer.
*/
var anchorPoint = CGPoint(x: 0.5, y: 0.5)

/// Overridden for NSCopying compatibility
override func copy(with zone: NSZone? = nil) -> Any {
let attribute = super.copy(with: zone) as! SafariCollectionViewLayoutAttributes
attribute.anchorPoint = self.anchorPoint
return attribute

}


/// Overridden for Equatable compatibility
override func isEqual(_ object: Any?) -> Bool {
guard let object = object as? SafariCollectionViewLayoutAttributes,
object.anchorPoint == self.anchorPoint else {
Expand Down
4 changes: 2 additions & 2 deletions StoriesLayout.podspec
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'StoriesLayout'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'An Instagram Stories like UICollectionViewLayout'
s.swift_version = '5.0'
s.description = <<-DESC
Expand All @@ -12,7 +12,7 @@ just use StoriesCollectionViewLayout in your UICollectionView and subclass your
s.homepage = 'https://github.com/Oni-zerone/CollectionLayouts'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Andrea Altea' => 'oni.zerone@gmail.com' }
s.source = { :git => 'https://github.com/Oni-zerone/CollectionLayouts.git', :tag => s.version.to_s }
s.source = { :git => 'https://github.com/Oni-zerone/CollectionLayouts.git', :tag => 'StoriesLayout-' + s.version.to_s }
s.social_media_url = 'https://twitter.com/Oni_zerone'

s.ios.deployment_target = '10.0'
Expand Down
3 changes: 3 additions & 0 deletions StoriesLayout/Classes/StoriesCollectionViewCell.swift
Expand Up @@ -8,6 +8,9 @@
import UIKit
import CoreGraphics

/**
StoriesCollectionViewCell is a base class that you could use to create your custom cells with the Instagram Stories experience.
*/
open class StoriesCollectionViewCell: UICollectionViewCell {

public weak var gradientLayer: CAGradientLayer?
Expand Down
12 changes: 12 additions & 0 deletions StoriesLayout/Classes/StoriesCollectionViewLayout.swift
Expand Up @@ -7,6 +7,13 @@

import UIKit

/**
A concrete layout object that reproduce the look and feel of the Instagram Stories layout.
The items will be shown in a single row, one by one with the same dimension of the screen.
Actually there isn't a specific delegate to customize layout behviors of the cells.
*/
public class StoriesCollectionViewLayout: UICollectionViewLayout {

public var baseTransform: CATransform3D = {
Expand All @@ -15,6 +22,11 @@ public class StoriesCollectionViewLayout: UICollectionViewLayout {
return transform
}()

/**
Defines the contentSize of the collectionView
Actually StoriesCollectionViewLayout can handle a single section and the cell size is determined as the same of the collection.
*/
override public var collectionViewContentSize: CGSize {
guard let collectionView = collectionView,
let dataSource = collectionView.dataSource else { return .zero }
Expand Down
25 changes: 23 additions & 2 deletions StoriesLayout/Classes/StoriesLayoutAttributes.swift
Expand Up @@ -6,15 +6,36 @@
//

import UIKit

/**
The custom `UICollectionViewLayoutAttributes` subclass used by `StoriesCollectionViewLayout`
*/
public class StoriesLayoutAttributes: UICollectionViewLayoutAttributes {


/**
The gradient informations used by the `StoriesCollectionViewCell`
*/
public enum Gradient: Equatable {
case left(percent: Float)
case right(percent: Float)
}

/**
Anchor point is the realtive position used to calculate the rotation transformation of the cell.
If you won't use the `StoriesCollectionViewCell` as your base cell class remember to override
`func apply(_ layoutAttributes: UICollectionViewLayoutAttributes)` method to pass the anchorPoint property
to the cell layer.
*/
var anchorPoint: CGPoint = CGPoint(x: 0.5, y: 0.5)

/**
Gradient informations to render the `CAGradientLayer` over the `UICollectionViewCell`.
If you won't use the `StoriesCollectionViewCell` as your base cell class remember to override
`func apply(_ layoutAttributes: UICollectionViewLayoutAttributes)` method to draw the `CAGradientLayer` if you want to show it.
*/
var gradient: Gradient?

override public func copy(with zone: NSZone? = nil) -> Any {
Expand Down

0 comments on commit 28ef880

Please sign in to comment.