Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
UICollectionView Basics and Flow Layout
Search
Maciej Oczko
November 29, 2014
Programming
0
240
UICollectionView Basics and Flow Layout
Basics of UICollectionView and Flow Layout for workshops in Kraków.
Maciej Oczko
November 29, 2014
Tweet
Share
More Decks by Maciej Oczko
See All by Maciej Oczko
Dependency Injection on iOS
maciejoczko
1
130
Working with Legacy Code (Łódź)
maciejoczko
0
54
iOS TDD Workshop (Gdańsk)
maciejoczko
1
81
UICollectionView Introduction
maciejoczko
0
62
Working With Legacy Code - iOS TDD Workshop
maciejoczko
0
170
Depenedency Injection in iOS
maciejoczko
0
70
Other Decks in Programming
See All in Programming
タスクの特性や不確実性に応じた最適な作業スタイルの選択(ペアプロ・モブプロ・ソロプロ)と実践 / Optimal Work Style Selection: Pair, Mob, or Solo Programming.
honyanya
3
190
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
250
Claude CodeによるAI駆動開発の実践 〜そこから見えてきたこれからのプログラミング〜
iriikeita
0
320
釣り地図SNSにおける有料機能の実装
nokonoko1203
0
200
XP, Testing and ninja testing ZOZ5
m_seki
3
810
NIKKEI Tech Talk#38
cipepser
0
150
monorepo の Go テストをはやくした〜い!~最小の依存解決への道のり~ / faster-testing-of-monorepos
convto
2
530
Developer Joy - The New Paradigm
hollycummins
1
350
AI Agent 時代的開發者生存指南
eddie
4
2.1k
CSC305 Lecture 08
javiergs
PRO
0
270
Six and a half ridiculous things to do with Quarkus
hollycummins
0
210
What's new in Spring Modulith?
olivergierke
1
170
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
49
14k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Leading Effective Engineering Teams in the AI Era
addyosmani
7
580
Done Done
chrislema
185
16k
Faster Mobile Websites
deanohume
310
31k
The Invisible Side of Design
smashingmag
302
51k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
Documentation Writing (for coders)
carmenintech
75
5.1k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Transcript
UICollectionView #UICollectionViewKrakow
@maciejoczko #UICollectionViewKrakow
Introduction #UICollectionViewKrakow
UI != NS #UICollectionViewKrakow
#UICollectionViewKrakow
“UICollectionView is the new UITableView. It's that important. NSHipster #UICollectionViewKrakow
“UICollectionView is awesome! My Friend #UICollectionViewKrakow
“The UICollectionView class manages an ordered collection of data items
and presents them using customizable layouts. Apple #UICollectionViewKrakow
UICollectionView allows » to have totally custom layout » to
dynamically change layouts » to have interactive transitions between layouts #UICollectionViewKrakow
UICollectionView is » subclass of UIScrollView » sibling of UITableView
#UICollectionViewKrakow
UICollectionView Alloc Init » initWithFrame:collectionViewLayout: » UICollectionViewController #UICollectionViewKrakow
UICollectionView is mostly about... #UICollectionViewKrakow
Grids #UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
#UICollectionViewKrakow
Anatomy of Collection View #UICollectionViewKrakow
Cell Supplementary View Decoration View #UICollectionViewKrakow
Cell For Item » Tied to content » No predefined
style » New way of creation » UICollectionReusableView subclass #UICollectionViewKrakow
Supplementary View » Tied to content but separate from cells
» Driven by section data » View of a kind » UICollectionReusableView subclass #UICollectionViewKrakow
Decoration View » Not tied to content » Created in
layout subclass » UICollectionReusableView subclass #UICollectionViewKrakow
Layout #UICollectionViewKrakow
Layout: Position #UICollectionViewKrakow
Layout: animations & transitions #UICollectionViewKrakow
How to create custom layout? #UICollectionViewKrakow
Derive from UICollectionViewLayout #UICollectionViewKrakow
Override methods collectionViewContentSize layoutAttributesForElementsInRect: layoutAttributesForItemAtIndexPath: layoutAttributesForSupplementaryViewOfKind:atIndexPath: layoutAttributesForDecorationViewOfKind:atIndexPath: shouldInvalidateLayoutForBoundsChange: #UICollectionViewKrakow
Override even more... prepareForCollectionViewUpdates: initialLayoutAttributesForAppearingItemAtIndexPath: initialLayoutAttributesForAppearingSupplementaryElementOfKind:atIndexPath: initialLayoutAttributesForAppearingDecorationElementOfKind:atIndexPath: finalLayoutAttributesForDisappearingItemAtIndexPath: finalLayoutAttributesForDisappearingSupplementaryElementOfKind:atIndexPath: finalLayoutAttributesForDisappearingDecorationElementOfKind:atIndexPath:
finalizeCollectionViewUpdates #UICollectionViewKrakow
Attributes1 Object that manages the layout-related attributes for a given
item. 1 UICollectionViewLayoutAttributes #UICollectionViewKrakow
Attributes1 » frame, center, size » alpha, hidden » zIndex
» transform 3D 1 UICollectionViewLayoutAttributes #UICollectionViewKrakow
Layout: Recap » positioning » animations & transitions » subclassing
» UICollectionViewLayoutAttributes #UICollectionViewKrakow
Data Source Delegate #UICollectionViewKrakow
Delegate » Selection & highlight tracking callbacks » Tracking the
removal of views » Layout transition callback » Menu actions callbacks #UICollectionViewKrakow
Data Source - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section -
(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath #UICollectionViewKrakow
Data Source - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath #UICollectionViewKrakow
collectionView:cellForItemAtIndexPath: MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@”MY_CELL_ID”]; if (!cell) { cell
= . . . } // Configure the cell's content return cell; #UICollectionViewKrakow
collectionView:cellForItemAtIndexPath: MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@”MY_CELL_ID” forIndexPath:indexPath]; // Configure the
cell's content return cell; #UICollectionViewKrakow
View class registration [collectionView registerClass:[MyCell class] forCellWithReuseIdentifier:@“MY_CELL_ID”] [collectionView registerClass:[MySupView class]
forSupplementaryViewOfKind:@“MY_KIND” withReuseIdentifier:@“MY_CELL_ID”] [collectionView registerClass:[MyDecoView class] forDecorationViewOfKind:@“MY_KIND”] #UICollectionViewKrakow
Flow Layout #UICollectionViewKrakow
Flow Layout3 » Line oriented » Grid or group of
lines » Predefined supplementary views: header & footer 3 UICollectionViewFlowLayout #UICollectionViewKrakow
Flow Layout: Customization » itemsize » inter item spacing »
line spacing » scroll direction2 » reference sizes » section insets 2 Can't be set through UICollectionViewDelegateFlowLayout delegate. #UICollectionViewKrakow
Flow Layout #UICollectionViewKrakow
RECAP UICollectionView Anatomy Layout & Attributes Data Source & Delegate
Flow Layout #UICollectionViewKrakow
https://github.com/mobile-academy/ ios-uicollectionview-seed #UICollectionViewKrakow
Task Create simple CollectionViewController with flow layout and inject it
to RootViewController as its content. // AppDelegate.m CollectionViewDataSource *dataSource = [CollectionViewDataSource new]; CollectionViewController *cVC = [[CollectionViewController alloc] initWithDataSource:dataSource]; RootViewController *rootVC = [[RootViewController alloc] initWithContentController:cVC]; self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:rootVC]; #UICollectionViewKrakow
#UICollectionViewKrakow #UICollectionViewKrakow
Thanks! @maciejoczko #UICollectionViewKrakow