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
iosdc_2017.pdf
Search
Kyohei Ito
September 17, 2017
940
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
iosdc_2017.pdf
Kyohei Ito
September 17, 2017
More Decks by Kyohei Ito
See All by Kyohei Ito
flutter_kaigi_2025.pdf
kyoheig3
2
1k
layerx_20241129.pdf
kyoheig3
2
520
flutterkaigi_2024.pdf
kyoheig3
0
1.8k
flutter_kaigi_2021.pdf
kyoheig3
0
1.2k
flutter_kmm_1.pdf
kyoheig3
1
1.2k
ca.swift_10.pdf
kyoheig3
0
720
iosdc_2018.pdf
kyoheig3
2
3.2k
orecon_vol1.pdf
kyoheig3
4
1.8k
ca.swift_2.pdf
kyoheig3
9
1.4k
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
180
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
210
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.4k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Ethics towards AI in product and experience design
skipperchong
2
330
Into the Great Unknown - MozCon
thekraken
41
2.6k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
340
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
220
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.6k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Unsuck your backbone
ammeep
672
58k
Transcript
࠷ۙͷ͋ͷαʔϏεͷ ൪දͷ࣮Λඥղ͘ 2017/09/17 iOSDC
About Me ҏ౻ɹګฏ Github : KyoheiG3 Twitter : @KyoheiG3
None
None
։ൃॳͷཁ݅ • 300νϟϯωϧදࣔ • ԣεΫϩʔϧͷίϯςϯπͷϧʔϓʢແݶεΫϩʔϧʣ
ͬͨ͜ͱ • UIScrollView on UITableView • UICollectionView • UIScrollView on
UIScrollView • UIScrollView
UIScrollView on UITableView
UIScrollView on UITableView • શνϟϯωϧͷUITableViewΛฒΔ • ݟ͍͑ͯΔ෦͚ͩUITableViewΛฒΔ
શνϟϯωϧͷUITableViewΛฒΔ Good • ࣮ͷΠϝʔδ͕͠қ͍ • ݁ߏαΫοͱͰ͖Δ
શνϟϯωϧͷUITableViewΛฒΔ Bad • ϝϞϦ͕ࢮ͵ • ॎεΫϩʔϧ͕ॏ͍
ݟ͍͑ͯΔ෦͚ͩUITableViewΛฒΔ Good • ϝϞϦͷ༻ྔΛݮͰ͖Δ
ݟ͍͑ͯΔ෦͚ͩUITableViewΛฒΔ Bad • UITableViewͷ࠶ར༻͕ॏ͍ • ࣮͕ෳࡶʹͳΔ
ແݶεΫϩʔϧ • UITableViewͷxҐஔมߋͰରԠͰ͖ͦ͏
UITableViewॏ͍..
UICollectionView
https://github.com/KyoheiG3/CollectionViewGridLayout
CollectionViewGridLayout Good • Cellͷෑ͖٧Ίࣗମ݁ߏ͍͍ײ͡ • isPrefetchingEnabledfalseʹ͢Δ
isPrefetchingEnabled දࣔൣғΑΓൣғʹCellΛ४උ
isPrefetchingEnabled දࣔൣғΑΓൣғʹCellΛ४උ
CollectionViewGridLayout Bad • CellͷαΠζมߋΛ͢ΔΑ͏ͳΞχϝʔγϣϯ͕໘ • ແݶεΫϩʔϧ͕Πέͯͳ͍
ແݶεΫϩʔϧ delegateͱdataSourceଆͰͦΕΛҙࣝͤ͟ΔΛಘͳ͍
let list: [String] = ["1", "2", "3", "4", "5"] func
collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return list.count * 2 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionViewCell cell.label.text = list[indexPath.item % list.count] return cell }
ແݶεΫϩʔϧ
ແݶεΫϩʔϧ
UICollectionViewCellͷ࠶ར༻Λ࠷దԽͰ͖ͳ͍...
UIScrollView on UIScrollView
https://github.com/KyoheiG3/InfiniteView
InfiniteView • UIScrollViewͰ࡞ͨ͠UITableViewͷΑ͏ͳͷ • Cellͷ࠶ར༻Λͯ͢ཧ • CellͷϨΠΞτʹAutoLayoutΛར༻ • ΠϯλʔϑΣΠεUICollectionViewͷΑ͏ͳײ͡
InfiniteView Good • ΞχϝʔγϣϯͳͲAutoLayoutશ։Ͱ࣮Ͱ͖ͨ • ίϯτϩʔϥʔଆεοΩϦ • ແݶεΫϩʔϧ
InfiniteView Bad • Cellͷ࠶ར༻ͳͲϨΠϠʔͳ෦ͷ࣮ͳͲෳࡶͩͬͨ • CellͷαΠζมߋͷΞχϝʔγϣϯ͕ෳࡶͩͬͨ • ͱʹ͔͘ෳࡶͩͬͨ
ॳ৺ʹؼΖ͏
UIScrollView
https://github.com/KyoheiG3/GridView
ཁ݅ • εϜʔζͳεΫϩʔϧΛՄೳʹ͢Δ • CellͷαΠζΛΞχϝʔγϣϯͰมߋ͢Δ͜ͱ͕Ͱ͖Δ • ͳΜͳΒ֦ॖ͍ͨ͠Μ͚ͩͲͱ͍͏ཁʹ͑Δ • ϖʔδϯάͰ͖ΔΑ͏ʹ͢Δ
֓ཁ • 1ຕͷUIScrollViewͷ্ʹCellͷView͕ࡌ͍ͬͯΔ͚ͩ • AutoLayoutະ༻ • ແݶεΫϩʔϧCellͷframeͷมߋ
ॲཧ • contentOffsetมߋલͱมߋޙͷࠩܭࢉ • ֦ॖͷ߹ࠩܭࢉ • ճస֦ॖͷΞχϝʔγϣϯ࣌ࠩܭࢉ
ࠩܭࢉ 1. දࣔൣғͷCellใΛArrayͰอ࣋ 2. contentOffset͕มߋ͞Εͨ͋ͱͷ දࣔൣғͷCellใΛܭࢉ 3. ඞཁແ͘ͳͬͨCellΛআ 4. ৽ͨʹද͕ࣔඞཁʹͳΔCellͷՃ
ࠩܭࢉ 1. දࣔൣғͷCellใΛArrayͰอ࣋ 2. contentOffset͕มߋ͞Εͨ͋ͱͷ දࣔൣғͷCellใΛܭࢉ 3. ඞཁແ͘ͳͬͨCellΛআ 4. ৽ͨʹද͕ࣔඞཁʹͳΔCellͷՃ
ࠩܭࢉ 1. දࣔൣғͷCellใΛArrayͰอ࣋ 2. contentOffset͕มߋ͞Εͨ͋ͱͷ දࣔൣғͷCellใΛܭࢉ 3. ඞཁແ͘ͳͬͨCellΛআ 4. ৽ͨʹද͕ࣔඞཁʹͳΔCellͷՃ
൪දʹΈࠐΉ
UILabelͷattributedTextͬͯ͘͢͝ॏ͍ • AttributedLabelͬͯͷΛ࡞ͬͨ
AttributedLabelͷύϑΥʔϚϯε • Viewʹdraw • intrinsicContentSizeͷݺͼग़͠Λඞཁ࠷ݶ
intrinsicContentSizeͱ • ίϯςϯπͷ༰ʹԠͯ͡αΠζ͕ࣗಈతʹมΘΔViewΛ࡞ Ͱ͖Δ • UILabelUIButton͕͜ΕʹରԠ͍ͯ͠Δ
UILabelͷڍಈ • invalidateIntrinsicContentSizeͷݺͼग़͠ var text: String? { didSet { invalidateIntrinsicContentSize()
} } var font: UIFont! { didSet { invalidateIntrinsicContentSize() } }
UILabelͷڍಈ • ίϯςϯπͷදࣔൣғΛࣗಈܭࢉ override var intrinsicContentSize: CGSize { // ίϯςϯπͷදࣔൣғΛܭࢉͯ͠ฦ͢
}
UILabelͷύϑΥʔϚϯε • දࣔαΠζ͕ܾ·͍ͬͯΔ߹ͦͷαΠζΛฦ͢1 override var intrinsicContentSize: CGSize { return bounds.size
} 1 UITableViewCellͳͲͷࣗಈܭࢉॲཧ͏·͘ಈ͔ͳ͘ͳΓ·͢ɻ
UILabelͷύϑΥʔϚϯε • AttributedLabelΛར༻͢Δ !
AbemaTVͷ൪දͷCell • αΠζͷมߋ͕໌֬ͳ߹ʹ invalidateIntrinsicContentSize ΛݺͿ • intrinsicContentSize͕ࢀর͞Ε ͨΒsizeThatFitsͰαΠζΛܭࢉ͠ ͯฦ͢
ϨΠΞτॲཧΛԆ͢Δ
ϨΠΞτͷԆॲཧ • දࣔʹؔ͢ΔॲཧΛαϒεϨουͰߦ͏͜ͱͰ͖ͳ͍ • Cell͕දࣔ͞Ε͔ͯΒLabelΛϨΠΞτ͢Δ·Ͱͷ࣌ؒΛ গ͚ͩ͠σΟϨΠ
viewModel.currentContent .debounce(0.1, scheduler: MainScheduler.instance) .do(onNext: { [weak self] slot in
guard let me = self else { return } me.timeLabel.text = "00" me.titleLabel.attributedText = "Title" me.detailLabel.text = "Detail" }) .subscribe(onNext: { [weak self] content in guard let me = self else { return } me.titleLabel.invalidateIntrinsicContentSize() me.detailLabel.invalidateIntrinsicContentSize() me.layoutIfNeeded() }) .disposed(by: disposeBag)
ύϑΥʔϚϯεΛ্͢Δʹ • intrinsicContentSizeΛ੍ޚ • ඞཁʹԠͯ͡Ԇॲཧ
࠷ۙͷ͋ͷαʔϏεͷ൪දͷ࣮Λඥղ͘ https://github.com/KyoheiG3/CollectionViewGridLayout https://github.com/KyoheiG3/InfiniteView https://github.com/KyoheiG3/GridView Github : KyoheiG3 Twitter : @KyoheiG3
Thanks!