Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
iosdc_2017.pdf
Kyohei Ito
September 17, 2017
4
690
iosdc_2017.pdf
Kyohei Ito
September 17, 2017
Tweet
Share
More Decks by Kyohei Ito
See All by Kyohei Ito
flutter_kaigi_2021.pdf
kyoheig3
0
310
flutter_kmm_1.pdf
kyoheig3
1
690
ca.swift_10.pdf
kyoheig3
0
490
iosdc_2018.pdf
kyoheig3
2
2k
orecon_vol1.pdf
kyoheig3
4
1.2k
ca.swift_2.pdf
kyoheig3
9
990
ca.swift.pdf
kyoheig3
1
1.8k
protocol_buffers.pdf
kyoheig3
6
5.5k
abema_devcon.pdf
kyoheig3
8
6.4k
Featured
See All Featured
Optimizing for Happiness
mojombo
365
63k
Reflections from 52 weeks, 52 projects
jeffersonlam
337
17k
How GitHub (no longer) Works
holman
296
140k
The Most Common Mistakes in Cover Letters
jrick
PRO
4
24k
Agile that works and the tools we love
rasmusluckow
319
19k
Embracing the Ebb and Flow
colly
73
3.3k
Visualization
eitanlees
124
11k
Why You Should Never Use an ORM
jnunemaker
PRO
47
5.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
238
11k
Ruby is Unlike a Banana
tanoku
91
9.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
25
1.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
498
130k
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!