Commit 6a42c8f2 by Daniel Dahan

reverted changes to MaterialCollection*

parent ef45d307
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
......
......@@ -59,9 +59,9 @@ public class BarView : ControlView {
super.init(frame: frame)
}
/// Basic initializer.
public override init() {
super.init(leftControls: nil, rightControls: nil)
/// Convenience initializer.
public convenience init() {
self.init(frame: CGRectZero)
}
/**
......
......@@ -75,7 +75,7 @@ public class MaterialCollectionView : UICollectionView {
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset {
get {
return (collectionViewLayout as! MaterialCollectionViewLayout).contentInsetPreset
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset
}
set(value) {
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInsetPreset = value
......@@ -84,20 +84,20 @@ public class MaterialCollectionView : UICollectionView {
public override var contentInset: UIEdgeInsets {
get {
return (collectionViewLayout as! MaterialCollectionViewLayout).contentInset
return (collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset
}
set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).contentInset = value
(collectionViewLayout as? MaterialCollectionViewLayout)!.contentInset = value
}
}
/// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection {
get {
return (collectionViewLayout as! MaterialCollectionViewLayout).scrollDirection
return (collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection
}
set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).scrollDirection = value
(collectionViewLayout as? MaterialCollectionViewLayout)!.scrollDirection = value
}
}
......@@ -111,20 +111,10 @@ public class MaterialCollectionView : UICollectionView {
/// Spacing between items.
@IBInspectable public var spacing: CGFloat {
get {
return (collectionViewLayout as! MaterialCollectionViewLayout).spacing
return (collectionViewLayout as? MaterialCollectionViewLayout)!.spacing
}
set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).spacing = value
}
}
/// The layout alignment direction.
public var alignmentDirection: MaterialAlignmentDirection {
get {
return (collectionViewLayout as! MaterialCollectionViewLayout).alignmentDirection
}
set(value) {
(collectionViewLayout as! MaterialCollectionViewLayout).alignmentDirection = value
(collectionViewLayout as? MaterialCollectionViewLayout)!.spacing = value
}
}
......@@ -142,10 +132,7 @@ public class MaterialCollectionView : UICollectionView {
- Parameter collectionViewLayout: A UICollectionViewLayout reference.
*/
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
guard let l = layout as? MaterialCollectionViewLayout else {
assert(false, "[MaterialCollectionView Error: Must use a class that subclasses MaterialCollectionViewLayout]")
}
super.init(frame: frame, collectionViewLayout: l)
super.init(frame: frame, collectionViewLayout: layout)
prepareView()
}
......@@ -174,6 +161,5 @@ public class MaterialCollectionView : UICollectionView {
contentScaleFactor = MaterialDevice.scale
backgroundColor = MaterialColor.clear
contentInset = UIEdgeInsetsZero
alignmentDirection = .None
}
}
}
\ No newline at end of file
......@@ -30,16 +30,13 @@
import UIKit
public enum MaterialAlignmentDirection {
case None
case Vertical
case Horizontal
}
public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
public class MaterialCollectionViewLayout : UICollectionViewLayout {
/// Used to calculate the dimensions of the cells.
internal var offset: CGPoint = CGPointZero
/// The size of items.
public var itemSize: CGSize = CGSizeZero
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
......@@ -59,8 +56,8 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
/// Cell items.
public private(set) var items: Array<MaterialDataSourceItem>?
/// Alignment direction.
public var alignmentDirection: MaterialAlignmentDirection = .None
/// Scroll direction.
public var scrollDirection: UICollectionViewScrollDirection = .Vertical
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
......@@ -88,50 +85,32 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
}
public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForItemAtIndexPath(indexPath)!
let attributes: UICollectionViewLayoutAttributes = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath)
let item: MaterialDataSourceItem = items![indexPath.item]
switch alignmentDirection {
case .Vertical:
if 0 < itemSize.width && 0 < itemSize.height {
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, itemSize.height - contentInset.top - contentInset.bottom)
} else if .Vertical == scrollDirection {
attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, nil == item.height ? collectionView!.bounds.height : item.height!)
case .Horizontal:
} else {
attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, collectionView!.bounds.height - contentInset.top - contentInset.bottom)
case .None:
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, itemSize.height - contentInset.top - contentInset.bottom)
}
return attributes
}
public override func layoutAttributesForSupplementaryViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForSupplementaryViewOfKind(elementKind, atIndexPath: indexPath)!
let item: MaterialDataSourceItem = items![indexPath.item]
switch alignmentDirection {
case .Vertical:
attributes.frame = CGRectMake(contentInset.left, offset.y, collectionView!.bounds.width - contentInset.left - contentInset.right, 44)
case .Horizontal:
attributes.frame = CGRectMake(offset.x, contentInset.top, nil == item.width ? collectionView!.bounds.width : item.width!, 44)
case .None:
attributes.frame = CGRectMake(offset.x, offset.y, itemSize.width - contentInset.left - contentInset.right, headerReferenceSize.height - contentInset.top - contentInset.bottom)
}
return attributes
}
public override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes: Array<UICollectionViewLayoutAttributes> = super.layoutAttributesForElementsInRect(rect)!
return attributes
}
public override func layoutAttributesForDecorationViewOfKind(elementKind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
let attributes: UICollectionViewLayoutAttributes = super.layoutAttributesForDecorationViewOfKind(elementKind, atIndexPath: indexPath)!
return attributes
var layoutAttributes: Array<UICollectionViewLayoutAttributes> = Array<UICollectionViewLayoutAttributes>()
for (attribute, _) in layoutItems {
if CGRectIntersectsRect(rect, attribute.frame) {
layoutAttributes.append(attribute)
}
}
return layoutAttributes
}
public override func shouldInvalidateLayoutForBoundsChange(newBounds: CGRect) -> Bool {
return .Vertical == scrollDirection ? newBounds.width != collectionView?.bounds.width : newBounds.height != collectionView?.bounds.height
return .Vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height
}
public override func collectionViewContentSize() -> CGSize {
......@@ -157,10 +136,10 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
let item: MaterialDataSourceItem = items[i]
indexPath = NSIndexPath(forItem: i, inSection: 0)
layoutItems.append((layoutAttributesForItemAtIndexPath(indexPath!)!, indexPath!))
offset.x += spacing
offset.x += nil == item.width ? itemSize.width : item.width!
offset.y += spacing
offset.y += nil == item.height ? itemSize.height : item.height!
}
......@@ -168,17 +147,16 @@ public class MaterialCollectionViewLayout : UICollectionViewFlowLayout {
offset.x += contentInset.right - spacing
offset.y += contentInset.bottom - spacing
switch alignmentDirection {
case .Vertical:
if 0 < itemSize.width && 0 < itemSize.height {
contentSize = CGSizeMake(offset.x, offset.y)
} else if .Vertical == scrollDirection {
contentSize = CGSizeMake(collectionView!.bounds.width, offset.y)
case .Horizontal:
} else {
contentSize = CGSizeMake(offset.x, collectionView!.bounds.height)
case .None:
contentSize = CGSizeMake(offset.x, offset.y)
}
}
public override func targetContentOffsetForProposedContentOffset(proposedContentOffset: CGPoint) -> CGPoint {
return proposedContentOffset
}
}
}
\ No newline at end of file
......@@ -111,9 +111,9 @@ public class SearchBar : BarView {
super.init(frame: frame)
}
/// Basic initializer.
public override init() {
super.init()
/// Convenience initializer.
public convenience init() {
self.init(frame: CGRectZero)
}
/**
......
......@@ -74,9 +74,9 @@ public class Toolbar : BarView {
super.init(frame: frame)
}
/// Basic initializer.
public override init() {
super.init()
/// Convenience initializer.
public convenience init() {
self.init(frame: CGRectZero)
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment