Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
f8d7781b
Commit
f8d7781b
authored
Feb 24, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated MaterialCollectionViewLayout to take scale into account
parent
db20b06a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
21 deletions
+23
-21
Sources/MaterialCollectionViewDataSource.swift
+3
-2
Sources/MaterialCollectionViewLayout.swift
+20
-19
No files found.
Sources/MaterialCollectionViewDataSource.swift
View file @
f8d7781b
...
...
@@ -31,7 +31,7 @@
public
protocol
MaterialCollectionViewDataSource
:
MaterialDelegate
,
UICollectionViewDataSource
{
/**
/// Retrieves the items for the collectionView.
- Returns: An Array of MaterialCollectionViewDataSourceItem objects.
- Returns: An Array of
Arrays of
MaterialCollectionViewDataSourceItem objects.
*/
func
items
()
->
Array
<
MaterialCollectionViewDataSourceItem
>
func
items
()
->
Array
<
Array
<
MaterialCollectionViewDataSourceItem
>
>
}
\ No newline at end of file
Sources/MaterialCollectionViewLayout.swift
View file @
f8d7781b
...
...
@@ -36,22 +36,24 @@ public enum MaterialCollectionViewLayoutScrollDirection {
}
public
class
MaterialCollectionViewLayout
:
UICollectionViewLayout
{
/// Size of the content.
private
var
contentSize
:
CGSize
=
CGSizeZero
/// Layout attribute items.
private
var
layoutItems
:
Array
<
(
UICollectionViewLayoutAttributes
,
NSIndexPath
)
>
?
private
var
layoutItems
:
Array
<
(
UICollectionViewLayoutAttributes
,
NSIndexPath
)
>
=
Array
<
(
UICollectionViewLayoutAttributes
,
NSIndexPath
)
>
()
/// Used to calculate the dimensions of the cells.
private
var
offset
:
CGFloat
=
0
/// Cell items.
private
var
items
:
Array
<
MaterialCollectionViewDataSourceItem
>
?
private
var
items
:
Array
<
Array
<
MaterialCollectionViewDataSourceItem
>
>
?
/// Scroll direction.
public
var
scrollDirection
:
MaterialCollectionViewLayoutScrollDirection
=
.
Vertical
/// Scale of the screen.
public
var
scale
:
CGFloat
=
2
/**
Retrieves the index paths for the items within the passed in CGRect.
- Parameter rect: A CGRect that acts as the bounds to find the items within.
...
...
@@ -59,7 +61,7 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
*/
public
func
indexPathsOfItemsInRect
(
rect
:
CGRect
)
->
Array
<
NSIndexPath
>
{
var
paths
:
Array
<
NSIndexPath
>
=
Array
<
NSIndexPath
>
()
for
(
attribute
,
indexPath
)
in
layoutItems
!
{
for
(
attribute
,
indexPath
)
in
layoutItems
{
if
CGRectIntersectsRect
(
rect
,
attribute
.
frame
)
{
paths
.
append
(
indexPath
)
}
...
...
@@ -69,18 +71,13 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
public
override
func
layoutAttributesForItemAtIndexPath
(
indexPath
:
NSIndexPath
)
->
UICollectionViewLayoutAttributes
?
{
let
attributes
:
UICollectionViewLayoutAttributes
=
UICollectionViewLayoutAttributes
(
forCellWithIndexPath
:
indexPath
)
if
0
==
indexPath
.
row
{
offset
=
0
}
let
item
:
MaterialCollectionViewDataSourceItem
=
items
!
[
indexPath
.
row
]
let
item
:
MaterialCollectionViewDataSourceItem
=
items
!
[
indexPath
.
section
][
indexPath
.
item
]
if
.
Vertical
==
scrollDirection
{
attributes
.
frame
=
CGRectMake
(
0
,
offset
,
collectionView
!.
bounds
.
width
,
item
.
size
.
height
)
attributes
.
frame
=
CGRectMake
(
0
,
offset
/
scale
,
collectionView
!.
bounds
.
width
,
item
.
size
.
height
)
offset
+=
item
.
size
.
height
}
else
{
attributes
.
frame
=
CGRectMake
(
offset
,
0
,
item
.
size
.
width
,
collectionView
!.
bounds
.
height
)
attributes
.
frame
=
CGRectMake
(
offset
/
scale
,
0
,
item
.
size
.
width
,
collectionView
!.
bounds
.
height
)
offset
+=
item
.
size
.
width
}
...
...
@@ -89,7 +86,7 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
public
override
func
layoutAttributesForElementsInRect
(
rect
:
CGRect
)
->
[
UICollectionViewLayoutAttributes
]?
{
var
layoutAttributes
:
Array
<
UICollectionViewLayoutAttributes
>
=
Array
<
UICollectionViewLayoutAttributes
>
()
for
(
attribute
,
_
)
in
layoutItems
!
{
for
(
attribute
,
_
)
in
layoutItems
{
if
CGRectIntersectsRect
(
rect
,
attribute
.
frame
)
{
layoutAttributes
.
append
(
attribute
)
}
...
...
@@ -109,19 +106,23 @@ public class MaterialCollectionViewLayout : UICollectionViewLayout {
let
dataSource
:
MaterialCollectionViewDataSource
=
collectionView
!.
dataSource
as!
MaterialCollectionViewDataSource
items
=
dataSource
.
items
()
layoutItems
=
Array
<
(
UICollectionViewLayoutAttributes
,
NSIndexPath
)
>
()
layoutItems
.
removeAll
()
offset
=
0
var
indexPath
:
NSIndexPath
?
var
count
:
Int
=
0
for
item
in
items
!
{
indexPath
=
NSIndexPath
(
forItem
:
count
++
,
inSection
:
0
)
layoutItems
?
.
append
((
layoutAttributesForItemAtIndexPath
(
indexPath
!
)
!
,
indexPath
!
))
for
var
i
:
Int
=
0
,
l
:
Int
=
items
!.
count
;
i
<
l
;
++
i
{
let
v
:
Array
<
MaterialCollectionViewDataSourceItem
>
=
items
!
[
i
]
for
var
j
:
Int
=
0
,
k
:
Int
=
v
.
count
;
j
<
k
;
++
j
{
let
item
:
MaterialCollectionViewDataSourceItem
=
v
[
j
]
indexPath
=
NSIndexPath
(
forItem
:
j
,
inSection
:
i
)
layoutItems
.
append
((
layoutAttributesForItemAtIndexPath
(
indexPath
!
)
!
,
indexPath
!
))
offset
+=
.
Vertical
==
scrollDirection
?
item
.
size
.
height
:
item
.
size
.
width
}
}
contentSize
=
.
Vertical
==
scrollDirection
?
CGSizeMake
(
collectionView
!.
bounds
.
width
,
offset
)
:
CGSizeMake
(
offset
,
collectionView
!.
bounds
.
height
)
contentSize
=
.
Vertical
==
scrollDirection
?
CGSizeMake
(
collectionView
!.
bounds
.
width
,
offset
/
scale
)
:
CGSizeMake
(
offset
/
scale
,
collectionView
!.
bounds
.
height
)
offset
=
0
}
public
override
func
targetContentOffsetForProposedContentOffset
(
proposedContentOffset
:
CGPoint
)
->
CGPoint
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment