Slide 1

Slide 1 text

࠷ۙ࿩୊ͷ͋ͷαʔϏεͷ ൪૊දͷ࣮૷Λඥղ͘ 2017/09/17 iOSDC

Slide 2

Slide 2 text

About Me ҏ౻ɹګฏ Github : KyoheiG3 Twitter : @KyoheiG3

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

։ൃ౰ॳͷཁ݅ • 300νϟϯωϧදࣔ • ԣεΫϩʔϧͷίϯςϯπͷϧʔϓʢແݶεΫϩʔϧʣ

Slide 6

Slide 6 text

΍ͬͨ͜ͱ • UIScrollView on UITableView • UICollectionView • UIScrollView on UIScrollView • UIScrollView

Slide 7

Slide 7 text

UIScrollView on UITableView

Slide 8

Slide 8 text

UIScrollView on UITableView • શνϟϯωϧ෼ͷUITableViewΛฒ΂Δ • ݟ͍͑ͯΔ෦෼͚ͩUITableViewΛฒ΂Δ

Slide 9

Slide 9 text

શνϟϯωϧ෼ͷUITableViewΛฒ΂Δ Good • ࣮૷ͷΠϝʔδ͕͠қ͍ • ݁ߏαΫοͱͰ͖Δ

Slide 10

Slide 10 text

શνϟϯωϧ෼ͷUITableViewΛฒ΂Δ Bad • ϝϞϦ͕ࢮ͵ • ॎεΫϩʔϧ͕ॏ͍

Slide 11

Slide 11 text

ݟ͍͑ͯΔ෦෼͚ͩUITableViewΛฒ΂Δ Good • ϝϞϦͷ࢖༻ྔΛ࡟ݮͰ͖Δ

Slide 12

Slide 12 text

ݟ͍͑ͯΔ෦෼͚ͩUITableViewΛฒ΂Δ Bad • UITableViewͷ࠶ར༻͕ॏ͍ • ࣮૷͕ෳࡶʹͳΔ

Slide 13

Slide 13 text

ແݶεΫϩʔϧ • UITableViewͷxҐஔมߋͰରԠ͸Ͱ͖ͦ͏

Slide 14

Slide 14 text

UITableView͸ॏ͍..

Slide 15

Slide 15 text

UICollectionView

Slide 16

Slide 16 text

https://github.com/KyoheiG3/CollectionViewGridLayout

Slide 17

Slide 17 text

CollectionViewGridLayout Good • Cellͷෑ͖٧Ίࣗମ͸݁ߏ͍͍ײ͡ • isPrefetchingEnabled͸falseʹ͢Δ

Slide 18

Slide 18 text

isPrefetchingEnabled දࣔൣғΑΓ޿ൣғʹCellΛ४උ

Slide 19

Slide 19 text

isPrefetchingEnabled දࣔൣғΑΓ޿ൣғʹCellΛ४උ

Slide 20

Slide 20 text

CollectionViewGridLayout Bad • CellͷαΠζมߋΛ͢ΔΑ͏ͳΞχϝʔγϣϯ͕໘౗ • ແݶεΫϩʔϧ͕Πέͯͳ͍

Slide 21

Slide 21 text

ແݶεΫϩʔϧ delegateͱdataSourceଆͰͦΕΛҙࣝͤ͟ΔΛಘͳ͍

Slide 22

Slide 22 text

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 }

Slide 23

Slide 23 text

ແݶεΫϩʔϧ

Slide 24

Slide 24 text

ແݶεΫϩʔϧ

Slide 25

Slide 25 text

UICollectionView͸Cellͷ࠶ར༻Λ࠷దԽͰ͖ͳ͍...

Slide 26

Slide 26 text

UIScrollView on UIScrollView

Slide 27

Slide 27 text

https://github.com/KyoheiG3/InfiniteView

Slide 28

Slide 28 text

InfiniteView • UIScrollViewͰ࡞੒ͨ͠UITableViewͷΑ͏ͳ΋ͷ • Cellͷ࠶ར༻Λ͢΂ͯ؅ཧ • CellͷϨΠΞ΢τʹAutoLayoutΛར༻ • ΠϯλʔϑΣΠε͸UICollectionViewͷΑ͏ͳײ͡

Slide 29

Slide 29 text

InfiniteView Good • ΞχϝʔγϣϯͳͲAutoLayoutશ։Ͱ࣮૷Ͱ͖ͨ • ίϯτϩʔϥʔଆ͸εοΩϦ • ແݶεΫϩʔϧ

Slide 30

Slide 30 text

InfiniteView Bad • Cellͷ࠶ར༻ͳͲ௿ϨΠϠʔͳ෦෼ͷ࣮૷ͳͲෳࡶͩͬͨ • CellͷαΠζมߋͷΞχϝʔγϣϯ͕ෳࡶͩͬͨ • ͱʹ͔͘ෳࡶͩͬͨ

Slide 31

Slide 31 text

ॳ৺ʹؼΖ͏

Slide 32

Slide 32 text

UIScrollView

Slide 33

Slide 33 text

https://github.com/KyoheiG3/GridView

Slide 34

Slide 34 text

ཁ݅ • εϜʔζͳεΫϩʔϧΛՄೳʹ͢Δ • CellͷαΠζΛΞχϝʔγϣϯͰมߋ͢Δ͜ͱ͕Ͱ͖Δ • ͳΜͳΒ֦ॖ͍ͨ͠Μ͚ͩͲͱ͍͏ཁ๬ʹ౴͑Δ • ϖʔδϯά΋Ͱ͖ΔΑ͏ʹ͢Δ

Slide 35

Slide 35 text

֓ཁ • 1ຕͷUIScrollViewͷ্ʹCellͷView͕ࡌ͍ͬͯΔ͚ͩ • AutoLayoutະ࢖༻ • ແݶεΫϩʔϧ͸Cellͷframeͷมߋ

Slide 36

Slide 36 text

ॲཧ • contentOffsetมߋલͱมߋޙͷࠩ෼ܭࢉ • ֦ॖͷ৔߹΋ࠩ෼ܭࢉ • ճస΍֦ॖͷΞχϝʔγϣϯ࣌΋ࠩ෼ܭࢉ

Slide 37

Slide 37 text

ࠩ෼ܭࢉ 1. දࣔൣғͷCell৘ใΛArrayͰอ࣋ 2. contentOffset͕มߋ͞Εͨ͋ͱͷ දࣔൣғͷCell৘ใΛܭࢉ 3. ඞཁແ͘ͳͬͨCellΛ࡟আ 4. ৽ͨʹද͕ࣔඞཁʹͳΔCellͷ௥Ճ

Slide 38

Slide 38 text

ࠩ෼ܭࢉ 1. දࣔൣғͷCell৘ใΛArrayͰอ࣋ 2. contentOffset͕มߋ͞Εͨ͋ͱͷ දࣔൣғͷCell৘ใΛܭࢉ 3. ඞཁແ͘ͳͬͨCellΛ࡟আ 4. ৽ͨʹද͕ࣔඞཁʹͳΔCellͷ௥Ճ

Slide 39

Slide 39 text

ࠩ෼ܭࢉ 1. දࣔൣғͷCell৘ใΛArrayͰอ࣋ 2. contentOffset͕มߋ͞Εͨ͋ͱͷ දࣔൣғͷCell৘ใΛܭࢉ 3. ඞཁແ͘ͳͬͨCellΛ࡟আ 4. ৽ͨʹද͕ࣔඞཁʹͳΔCellͷ௥Ճ

Slide 40

Slide 40 text

൪૊දʹ૊ΈࠐΉ

Slide 41

Slide 41 text

UILabelͷattributedTextͬͯ͘͢͝ॏ͍ • AttributedLabelͬͯͷΛ࡞ͬͨ

Slide 42

Slide 42 text

AttributedLabelͷύϑΥʔϚϯε • Viewʹ௚઀draw • intrinsicContentSizeͷݺͼग़͠Λඞཁ࠷௿ݶ

Slide 43

Slide 43 text

intrinsicContentSizeͱ͸ • ίϯςϯπͷ಺༰ʹԠͯ͡αΠζ͕ࣗಈతʹมΘΔViewΛ࡞ ੒Ͱ͖Δ • UILabel΍UIButton͕͜ΕʹରԠ͍ͯ͠Δ

Slide 44

Slide 44 text

UILabelͷڍಈ • invalidateIntrinsicContentSizeͷݺͼग़͠ var text: String? { didSet { invalidateIntrinsicContentSize() } } var font: UIFont! { didSet { invalidateIntrinsicContentSize() } }

Slide 45

Slide 45 text

UILabelͷڍಈ • ίϯςϯπͷදࣔൣғΛࣗಈܭࢉ override var intrinsicContentSize: CGSize { // ίϯςϯπͷදࣔൣғΛܭࢉͯ͠ฦ͢ }

Slide 46

Slide 46 text

UILabelͷύϑΥʔϚϯε • දࣔαΠζ͕ܾ·͍ͬͯΔ৔߹͸ͦͷαΠζΛฦ͢1 override var intrinsicContentSize: CGSize { return bounds.size } 1 UITableViewCellͳͲͷࣗಈܭࢉॲཧ͸͏·͘ಈ͔ͳ͘ͳΓ·͢ɻ

Slide 47

Slide 47 text

UILabelͷύϑΥʔϚϯε • AttributedLabelΛར༻͢Δ !

Slide 48

Slide 48 text

AbemaTVͷ൪૊දͷCell • αΠζͷมߋ͕໌֬ͳ৔߹ʹ invalidateIntrinsicContentSize ΛݺͿ • intrinsicContentSize͕ࢀর͞Ε ͨΒsizeThatFitsͰαΠζΛܭࢉ͠ ͯฦ͢

Slide 49

Slide 49 text

ϨΠΞ΢τॲཧΛ஗Ԇ͢Δ

Slide 50

Slide 50 text

ϨΠΞ΢τͷ஗Ԇॲཧ • දࣔʹؔ͢ΔॲཧΛαϒεϨουͰߦ͏͜ͱ͸Ͱ͖ͳ͍ • Cell͕දࣔ͞Ε͔ͯΒLabelΛϨΠΞ΢τ͢Δ·Ͱͷ࣌ؒΛ গ͚ͩ͠σΟϨΠ

Slide 51

Slide 51 text

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)

Slide 52

Slide 52 text

ύϑΥʔϚϯεΛ޲্͢Δʹ͸ • intrinsicContentSizeΛ੍ޚ • ඞཁʹԠͯ͡஗Ԇॲཧ

Slide 53

Slide 53 text

࠷ۙ࿩୊ͷ͋ͷαʔϏεͷ൪૊දͷ࣮૷Λඥղ͘ https://github.com/KyoheiG3/CollectionViewGridLayout https://github.com/KyoheiG3/InfiniteView https://github.com/KyoheiG3/GridView Github : KyoheiG3 Twitter : @KyoheiG3

Slide 54

Slide 54 text

Thanks!