Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iosdc_2017.pdf

4d40d82cc3c676e8a67ffc2a473bf423?s=47 Kyohei Ito
September 17, 2017
650

 iosdc_2017.pdf

4d40d82cc3c676e8a67ffc2a473bf423?s=128

Kyohei Ito

September 17, 2017
Tweet

Transcript

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

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

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

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

    UIScrollView • UIScrollView
  7. UIScrollView on UITableView

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

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

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

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

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

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

  14. UITableView͸ॏ͍..

  15. UICollectionView

  16. https://github.com/KyoheiG3/CollectionViewGridLayout

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

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

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

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

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

  22. 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 }
  23. ແݶεΫϩʔϧ

  24. ແݶεΫϩʔϧ

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

  26. UIScrollView on UIScrollView

  27. https://github.com/KyoheiG3/InfiniteView

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

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

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

  31. ॳ৺ʹؼΖ͏

  32. UIScrollView

  33. https://github.com/KyoheiG3/GridView

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

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

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

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

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

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

  40. ൪૊දʹ૊ΈࠐΉ

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

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

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

  44. UILabelͷڍಈ • invalidateIntrinsicContentSizeͷݺͼग़͠ var text: String? { didSet { invalidateIntrinsicContentSize()

    } } var font: UIFont! { didSet { invalidateIntrinsicContentSize() } }
  45. UILabelͷڍಈ • ίϯςϯπͷදࣔൣғΛࣗಈܭࢉ override var intrinsicContentSize: CGSize { // ίϯςϯπͷදࣔൣғΛܭࢉͯ͠ฦ͢

    }
  46. UILabelͷύϑΥʔϚϯε • දࣔαΠζ͕ܾ·͍ͬͯΔ৔߹͸ͦͷαΠζΛฦ͢1 override var intrinsicContentSize: CGSize { return bounds.size

    } 1 UITableViewCellͳͲͷࣗಈܭࢉॲཧ͸͏·͘ಈ͔ͳ͘ͳΓ·͢ɻ
  47. UILabelͷύϑΥʔϚϯε • AttributedLabelΛར༻͢Δ !

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

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

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

  51. 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)
  52. ύϑΥʔϚϯεΛ޲্͢Δʹ͸ • intrinsicContentSizeΛ੍ޚ • ඞཁʹԠͯ͡஗Ԇॲཧ

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

  54. Thanks!