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
The Pragmatic Product Professional
lauravandoore
37
7.3k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Chasing Engaging Ingredients in Design
codingconduct
0
230
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Balancing Empowerment & Direction
lara
6
1.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
170
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
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!