【完全版】AutoLayoutエラー診断所 ~発狂しないためのデバッグ手法~

9d1961575e45a8286cdde5f86dbba312?s=47 akatsuki174
September 02, 2018

【完全版】AutoLayoutエラー診断所 ~発狂しないためのデバッグ手法~

2018/09/02 (日) iOSDC Japan 2018
その他関連資料はここらへんからたどれます。
http://akatsuki174.hatenablog.com/entry/20180820/1534723200

9d1961575e45a8286cdde5f86dbba312?s=128

akatsuki174

September 02, 2018
Tweet

Transcript

  1. Auto LayoutΤϥʔ਍அॴ ~ൃڰ͠ͳ͍ͨΊͷσόοάख๏~ @akatsuki174 iOSDC Japan 2018 2018/09/02(೔)

  2. ࣗݾ঺հ

  3. • ਢ౻ຘʢ@akatsuki174ʣ • גࣜձࣾZaim / iOSΤϯδχΞ • iOSDC Japan 2018

    ίΞελοϑ ࠙਌ձͷ೔ຊञ ͷҰ෦͸ ϫγ͕બΜͩ
  4. ࠓ೔ͷ಺༰

  5. None
  6. None
  7. None
  8. ͜Μͳ͓೰Έղܾ͠·͢ • Τϥʔग़ͯΔ͚ͲԿ͔ΒखΛ෇͚͍͍͔ͯΘ͔Βͳ͍ • ଞਓ͕࡞ͬͨϨΠΞ΢τͷվम͕ා͍ • ༏ઌ౓ͱ͔දࣔ/ඇදࣔͱ͔ෳࡶͰΘ͚͕Θ͔Βͳ͍ • σόοάख๏͕ϚϯωϦԽ͖ͯͯ͠ɺܹ͕ࢗ΄͍͠

  9. ໨࣍

  10. • ࣄྫͱͱ΋ʹσόοάख๏ΛֶͿ • ίϯιʔϧϩάಡΉܥ • ϏδϡΞϧ͔Β൑அ͢Δܥ • LLDB࢖͏ܥ • ղܾͷࢳޱΛݟ͚ͭΔίπ

  11. ࠓ೔ͷܗࣜ

  12. • ϥΠϒσόοΪϯάͰਐΊ·͢ • ͨ·ʹྫ͕ద੾͡Όͳ͍΍ͭ΋ɻڐͯ͠ɻ • εϥΠυࣗମ͸εΫγϣ෇͖Ͱ͍͋͛ͯ·͢ • αϯϓϧίʔυ • ໰୊ฤͱղ౴ฤ͕͋Γ·͢

    • ղઆ͸iOSDCޙ΋௥Ճ͍͖ͯ͠·͢ • https://github.com/akatsuki174/AutoLayoutDebugSample ੒ޭͨ͠Β ഥखʂ ׬શ൛͸ εϥΠυ໿ຕ
  13. Let’s Debugging ٩( •̀ω•́)و

  14. ίϯιʔϧϩάಡΉܥ

  15. CASE 1. WarningΛؤுͬͯಡΉ αϯϓϧίʔυ 8BSOJOH7JFXΑΓɻ

  16. Warningൃੜ ͷϚʔδϯ

  17. Demo ͜ͷষͷ͔͜͜Βઌ͸ɺ σϞͷεΫγϣΛషΓ෇͚ͨ΋ͷͰ͢

  18. ্͔ΒॱʹϩάͷҙຯΛ௫΋͏ ʮಉ࣌ʹຬͨͤͳ੍͍໿͕͋ͬͨΑɻ ͨͿΜ͜ͷதͷগͳ͘ͱ΋1ͭͷ੍໿͕͍Βͳ͍΍͔ͭͩΒɺ ૝ఆ֎ͷ੍໿Λݟ͚ͭͯɺ੍໿ͷ෇͚֎͠Λͯ͠Ͷɻʯ

  19. ո͍͠ՕॴपลͷAuto Layout৘ใ͕දࣔ͞Ε͍ͯΔɻ ͜ΕΛͺͬͱݟͯΘ͔ΔͳΒͦΕʹӽͨ͜͠ͱ͸ͳ͍ɻ ্͔ΒॱʹϩάͷҙຯΛ௫΋͏

  20. ্͔ΒॱʹϩάͷҙຯΛ௫΋͏ ͳΜͱͳ͘ɺਫฏํ޲ʹؔ͢Δهड़͕ଟͦ͏Ͱ͢ɻ ʮUIView-Encapsulated-Layout-xxxʯ͸γεςϜ͕ੜ੒੍ͨ͠໿Ͱɺ ม͑Δ͜ͱ͸Ͱ͖·ͤΜɻ1ͭͷ஫໨ϙΠϯτʹͳΓ·͢ɻ

  21. ʮ͍͍͔Μ͡ʹදࣔ͢ΔͨΊʹ͜ͷ੍໿͸յͤͯ͞΋Βͬͨʂʯ ͜ΕΛݟΔͱɺ͍͍ͩͨ ɾਫฏ / ਨ௚ͲͪΒͷ੍໿͕ؒҧ͍ͬͯΔͷ͔ ɾͲͷपล͕ؒҧ͍ͬͯΔͷ͔ ͕Θ͔Δɻ ্͔ΒॱʹϩάͷҙຯΛ௫΋͏

  22. ʮσόοΨͰΩϟον͢Δʹ͸UIViewAlertForUnsatisfiableConstraints ͰγϯϘϦοΫϒϨʔΫϙΠϯτΛுͬͯͶɻ UIConstraintBasedLayoutDebuggingΧςΰϦͷதʹ͋Δϝιου΋໾ ʹཱͭͱࢥ͏Αɻʯ ্͔ΒॱʹϩάͷҙຯΛ௫΋͏

  23. γεςϜ͸Ͳ͔ͬͷUIView.width = 320ͷ੍໿Λউखʹ࡞ͬͨ γεςϜ͸UIProgressView.width = 355ͷ੍໿Λউखʹյͨ͠ ͓΍ɺͦ͏͍͑͹… ৼΓฦͬͯΈΔ

  24. ৼΓฦͬͯΈΔ • ࠓ࣮ߦ͍ͯ͠Δͷ͸iPhone SEαΠζ୺຤ • SEαΠζͷԣ෯͸320 • ͜Εʹରͯ͠UIProgressView.width = 355

    + ࠨӈϚʔδϯ͕ ɹ֬อͰ͖ΔΘ͚͕ͳ͍…
  25. ϨΠΞ΢τΛݟ௚͢ ແବʹԣ෯ͷ੍໿͕ ෇͍͍ͯͨͷͰ࡟আ ղܾ

  26. CASE 2. WTF Auto Layout?Λ࢖͏ αϯϓϧίʔυ $PWFS7JFXΑΓɻ

  27. WTF Auto Layout? https://www.wtfautolayout.com/

  28. None
  29. ղੳͰ͖ͳ͍͜ͱ΋͋Δ

  30. ࡞Γ͍ͨ ϨΠΞ΢τ ←View ←Label

  31. Demo ͜ͷষͷ͔͜͜Βઌ͸ɺ σϞͷεΫγϣΛషΓ෇͚ͨ΋ͷͰ͢

  32. Warningൃੜ

  33. None
  34. ໌Β͔ʹ͓͔͍͠ʂʂ

  35. ͜ͷ੍໿͕ҙਤ௨Γ͡Όͳ͔ͬͨΒ translatesAutoresizingMaskIntoConstraintsΛ falseʹͯ͠ΈͯͶʂ

  36. ղܾ

  37. CASE 3. IdentifierΛ෇͚ͯݟ΍͘͢͢Δ αϯϓϧίʔυ $PWFS7JFXΑΓɻ

  38. Veiwʹରͯ͠෇͚Δ৔߹

  39. None
  40. None
  41. ੍໿ʹରͯ͠෇͚Δ৔߹

  42. None
  43. CASE 4. ੍໿Λग़ྗ͢Δ αϯϓϧίʔυ 4UBDL7JFXΑΓɻ

  44. constraints()Λ࢖ͬͯΈΔ • ͋Δviewʹରͯ͠෇͍͍ͯΔ੍໿Λऔಘ͢Δ͜ͱ͕Ͱ͖Δ • ͱΓ͋͑ͣΑ͘Θ͔Μͳ͍ɺϫʔχϯάग़ͯͳ͍͚Ͳ ɹ ͳΜ͔͓͔͍࣌͠ʹ࢖ͬͯΈΔ

  45. constraintsAffectingLayout(for:)Λ࢖ͬͯΈΔ • ͋Δviewʹରͯ͠෇͍͍ͯΔ੍໿Λɺ࣠Λࢦఆͯ͠ ɹऔಘ͢Δ͜ͱ͕Ͱ͖Δ • ҉໧తͳ੍໿΋ؚ·ΕΔ • ӨڹΛ༩͑Δશͯͷ੍໿͕औಘͰ͖Δอূ͸ͳ͍

  46. ͜ͷෳࡶͳviewͰࢼͯ͠ΈΑ͏ stack view͍ͬͺ͍࢖ͬͯ·͢

  47. Demo ͜ͷষͷ͔͜͜Βઌ͸ɺ σϞͷεΫγϣΛషΓ෇͚ͨ΋ͷͰ͢

  48. ࢼ͠ʹԿ΋Τϥʔ͕ग़͍ͯͳ͍࣌ʹ Ұ൪Լʹ͋Δstack viewʹͲΜͳ੍໿͕ ෇͍͍ͯΔ͔ΛݟͯΈΔ

  49. Ϙλϯλοϓ࣌ʹϒϨʔΫϙΠϯτͰࢭΊͯ Ұ൪Լͷstack viewͷconstraintsΛग़ྗɻ ਫฏ / ਨ௚྆ํͷ੍໿͕ग़ྗ͞ΕΔɻ

  50. ಛఆͷ2ͭͷviewʹؔΘΔ੍໿ΛऔΓग़͍ͨ͠ͳΒ ͜ΜͳϝιουΛ࡞͓ͬͯ͘ͱศར

  51. Ұ൪Լͷstack viewͱself.viewؒʹ͋Δ੍໿Λग़ྗ

  52. ྘ͷviewͷਫฏํ޲ͷ੍໿͚ͩग़ྗ͍ͨ͠৔߹͸งғؾ͜Μͳ͔Μ͡

  53. ͨͩ͠ • ਫฏ / ਨ௚྆ํʹؔΘΔ੍໿͕·͔ͣͬͨ৔߹ɺ ɹ ͜ΕΛ΍ΔͱٯʹΘ͔Γʹ͍͘ ɹ ྫʣAspect RatioͳͲ

  54. CASE 5. γϯϘϦοΫϒϨʔΫϙΠϯτ

  55. γϯϘϦοΫϒϨʔΫϙΠϯτͱ͸ • ಛఆͷ৚݅ʹϚονͨ࣌͠ʹॲཧΛετοϓͯ͘͠ΕΔ • σόοάίϚϯυΛ࢓ࠐΉ͜ͱ΋Ͱ͖Δ • ೔ৗతʹᐆດͳϨΠΞ΢τͷݕ஌Λ͍ͨ࣌͠ɺϫʔχϯάͷ ɹՕॴΛಛఆ͍ͨ࣌͠ʹ࢖͏ͱྑ͍ʁ • Auto

    LayoutͷσόοάʹݶΒ͍ͣΖ͍Ζ࢖͍ಓ͸͋Δ
  56. γϯϘϦοΫϒϨʔΫϙΠϯτͷ௥Ճ

  57. γϯϘϦοΫϒϨʔΫϙΠϯτͷઃఆ expr -l objc++ -O -- [[UIWindow keyWindow] _autolayoutTrace] "EE"DUJPOΛ

    ΫϦοΫͯ͠ૠೖ
  58. ϒϨʔΫϙΠϯτ࢓ࠐΜͩ··࣮ߦ ᐆດͳϨΠΞ΢τ͕ඳը ͞ΕΔ࣌ʹετοϓͯ͠ ίϚϯυ͕࣮ߦ͞ΕΔ

  59. ϓϥΠϕʔτϝιου࢖͏ܥ

  60. ͜͜Ͱݴ͏ϓϥΠϕʔτϝιουͬͯʁ • Objective-Cʹ͓͚ΔɺϨΠΞ΢τΛσόοά͢Δͷʹ ɹ ศརͳϝιουͨͪ • SwiftͰ࢖͏ʹ͸࠶ఆٛɺϒϦοδ͢Δඞཁ͕͋Δ • ϦϦʔεϏϧυʹؚΊΔͱϦδΣΫτ͞ΕΔՄೳੑ͕͋ΔͷͰ ɹ

    ஫ҙ͕ඞཁ
  61. ผ్#SJEHJOH)FBEFSΛ ༻ҙ͢Δ

  62. CASE 6. hasAmbiguousLayoutΛ࢖͏

  63. hasAmbiguousLayout • ո͍͠viewʹରͯ͜͠ͷϝιουΛ࢖͏ • ੍໿ʹΑͬͯҐஔ͕Ұҙʹͳ͍ͬͯͳ͍ͱ͖ʹtrueΛฦ͢ • શͯͷᐆດͳϨΠΞ΢τΛݕ஌Ͱ͖ΔΘ͚Ͱ͸ͳ͍ • σόοάͷΈʹ༻͍Δ͜ͱ •

    αϒϏϡʔ·Ͱ࠶ؼతʹௐ΂ΔϝιουΛ࡞Δͱɺ ɹ ͲΕ͕ᐆດ͔ௐ΂΍ͯ͘͢ศར
  64. ࣗ෼͕ᐆດ͔Ͳ͏͔νΣοΫ ࣗ෼ͷࢠϏϡʔ͕ ᐆດ͔Ͳ͏͔νΣοΫ

  65. None
  66. ৄ͍͠৘ใΛ஌Γ͔ͨͬͨΒ [UIView _autolayoutTrace]Λ ࢖ͬͯͶ

  67. $PWFS7JFXʹᐆດͳ੍໿͕͋ΔΑ

  68. ཁ͢Δʹ6*-BCFM͕ո͍͠Α

  69. ͨͩ… • ίʔυͰAuto LayoutΛ࢖ͬͨͱ͖ʹߴ֬཰Ͱtrue͕ฦͬͯ ɹ ͘ΔΑ͏ͳؾ͕ͯ͠ɺ͍·͍ͪ৚͕݅Θ͔Βͳ͔ͬͨ • ࠷ॳ͸frame(0, 0, 0,

    0)͚ͩͲޙ͔Β translatesAutoresizingMaskIntoConstraintsΛfalseʹͯ͠ ɹ αΠζΛ͋ͯΔ৔߹΋true͕ฦͬͯདྷͯ͠·͏ • ͪͳΈʹStoryboard্Ͱ໌Β͔ʹΤϥʔ͕ग़͍ͯΔͱ͖͸ ɹ ੍໿͕ᐆດͰ΋falseΛฦ͢͜ͱ΋͋Δ༷ࢠ
  70. ཧ૝ͱͯ͠͸ • ͖ͬ͞࡞ͬͨhasAmbiguityϝιουΛ࢖ͬͯɺ ɹ XCTAssert(self.hasAmbiguity(), “Ambiguous Layout”)ͷΑ͏ʹ ɹϢχοτςετΛ΍Δͱྑ͍

  71. ิ଍ͱͯ͠ • exerciseAmbiguityInLayout()ϝιουͱ߹Θͤͯ࢖͏ͱྑ͍ • exerciseAmbiguityInLayout͸ᐆດͳ੍໿Λ࣋ͭviewͷ ɹ frameΛɺ੍໿Λຬͨ͢ൣғͰϥϯμϜʹมߋͯ͘͠ΕΔ

  72. αϒϏϡʔ·Ͱ ࠶ؼతʹ࣮ߦ λΠϚʔͰ ܁Γฦ࣮͠ߦ UIViewʹ͜ΜͳϝιουΛ࡞Δͱศར

  73. CASE 7. recursiveDescriptionΛ࢖͏

  74. recursiveDescriptionͱ͸ • ֘౰ͷviewͷ࠷ऴతͳϨΠΞ΢τͷϑϨʔϜͱ֊૚৘ใΛ ɹ ࠶ؼతʢ=recursiveʣʹදࣔͯ͘͠ΕΔ • Auto Layout৘ใ͸ೖ͍ͬͯͳ͍ • ௥Ճͨ͠͸ͣͷview͕දࣔ͞Ε͍ͯͳ͍ɺͳΜ͔มͳͱ͜Ζʹ

    ɹ දࣔ͞Ε͍ͯΔɺͳͲͷ৔߹ʹ࢖͏ͱྑ͍
  75. ͜ͷը໘Ͱࢼͯ͠ΈΔ (lldb) po [[UIWindow keyWindow] recursiveDescription]

  76. None
  77. WJFXͷ֊૚ߏ଄͕ Θ͔Δ Ұ෦ͷϓϩύςΟ͕ Θ͔Δ

  78. CASE 8. _autolayoutTraceΛ࢖͏

  79. _autolayoutTraceͱ͸ • viewͷ֊૚৘ใͱͦͷϨΠΞ΢τ੍͕໿ఆٛʹΑͬͯ ɹ ࣮ߦ͞Ε͍ͯΔ͔Ͳ͏͔Λදࣔ • ᐆດͳϨΠΞ΢τपลʹԿ͕ى͍ͬͯ͜Δͷ͔Λ೺Ѳ͠΍͍͢

  80. ͜ͷը໘Ͱࢼͯ͠ΈΔ (lldb) po [[UIWindow keyWindow] _autolayoutTrace]

  81. None
  82. ˎҹ͕෇͍͍ͯΔ΋ͷ͸ "VUP-BZPVUʹΑͬͯ ඳը͞Εͨ΋ͷ

  83. ʴҹ͕෇͍͍ͯΔ΋ͷ͸ "VUP-BZPVUΛ༻͍ͣ ඳըͨ͠΋ͷ

  84. ˔ҹ͕෇͍͍ͯΔ΋ͷ͸ ϨΠΞ΢τΤϯδϯͷ ϗετ

  85. CASE 9. _printHierarchyΛ࢖͏

  86. _printHierarchyͱ͸ • viewͷ֊૚৘ใͰ͸ͳ͘ɺview controllerͷ֊૚৘ใΛ ɹදࣔ͢Δ͜ͱ͕Ͱ͖Δ

  87. ͜ͷը໘Ͱࢼͯ͠ΈΔ (lldb) po [[[UIWindow keyWindow] rootViewController] _printHierarchy]

  88. ͜ͷը໘ͷ͜ͱ

  89. ͜ͷը໘ͷ͜ͱ

  90. ʛͰ͋Ε͹DIJMEWJFX DPOUSPMMFST ʴͰ͋Ε͹Ϟʔμϧ

  91. CASE 10. _ivarDescriptionΛ࢖͏

  92. _ivarDescriptionͱ͸ • ֘౰ͷΦϒδΣΫτ͕࣋ͭΠϯελϯεͱͦͷ஋Λ ɹ දࣔ͢Δ͜ͱ͕Ͱ͖Δ • Πϯελϯεͷੜ੒ɺॴ༗ͷ࣌఺Ͱؒҧ͍ͬͯΔͳͲͷཧ༝Ͱ ɹ ࠓ·ͰͷϝιουͰϨΠΞ΢τ৘ใΛ֬ೝͯ͠΋ ɹ͏·͘ղ໌Ͱ͖ͳ͍৔߹ͳͲʹ࢖͏

  93. • ͍͍ྫ͕ࢥ͍ු͔͹ͳ͔ͬͨͷͰ࣮ࢪྫ͸লུ

  94. ϏδϡΞϧ͔Β൑அ͢Δܥ

  95. CASE 11. cellͷߴ͞Λٙ͏ αϯϓϧίʔυ 7FSUJDBM-BCFMTΑΓɻ

  96. ࡞Γ͍ͨϨΠΞ΢τ ֤ཁૉؒʹͷ 伱ؒΛ΋ͨͤΔ

  97. Demo ͜ͷষͷ͔͜͜Βઌ͸ɺ σϞͷεΫγϣΛషΓ෇͚ͨ΋ͷͰ͢

  98. Τϥʔൃੜ ϫʔχϯάϩά͸ग़͍ͯͳ͍ɻ੍໿͸ಛʹ͓͔͘͠ͳ͍ɻ

  99. 4UPSZCPBSE্ͷDFMMͷߴ͞Λมߋͨ࣌͠఺Ͱ 3PX)FJHIU͕$VTUPNʹͳͬͯ ߴ͕͞ઃఆ͞ΕΔ cellϨΠΞ΢τΛ࡞Δ࣌…

  100. DFMMͷߴ͞Λमਖ਼ ੍໿ or ߴ͞Λमਖ਼͢Ε͹… Τϥʔղফ ղܾ

  101. CASE 12. ϏϡʔσόοΨʔΛ࢖͏ αϯϓϧίʔυ .VMUJ)JFSBSDIZ7JFXΑΓɻ

  102. ࡞Γ͍ͨϨΠΞ΢τ gray viewΛണ͕͢

  103. Կ͔͕͓͔͍͠ gray viewΛണ͕͢ ֊૚Λ೺Ѳ͢Δͷ͕ ྑͦ͞͏ʁ

  104. ϏϡʔσόοΨʔىಈ ͪΌΜͱ HSBZͷϏϡʔͷ্ʹ ৐͔ͬͬͯΔͬΆ͍ʁʁ ϏϡʔσόοΨʔͰ֬ೝ

  105. debug navigatorͰ֬ೝ ਌ࢠؔ܎ʹͳͬͯ ͍ͳ͔ͬͨ

  106. view֊૚Λमਖ਼ ਌ࢠؔ܎ʹͨ͠

  107. ׬੒

  108. CASE 13. contentHuggingPriorityΛ ௐ੔͢Δ αϯϓϧίʔυ 1SJPSJUZ7JFXΑΓɻ

  109.    ࡞Γ͍ͨϨΠΞ΢τ 5FYU'JFME͸Ͱ͖Δ͚ͩ ෯Λ޿͘औΔ

  110. Կ͔͕͓͔͍͠ 5FYU'JFME͕ ΊͬͪΌখ͍͞

  111. Կ͔͕͓͔͍͠ 1SJPSJUZӠʑ ݴΘΕͯΔ

  112. contentHuggingPriorityͱ͸ • େ͖͘ͳΓʹ͘͞ / ίϯςϯπʹԊ͏༏ઌ౓ • Hug = ԊͬͯਐΉͱ͍͏ҙຯ •

    ͜ͷ஋͕খ͍͞ͱଞͷ੍໿ʹӨڹ͞Εͯେ͖͘ͳΓ΍͘͢ͳΔ • ݻ༗αΠζΑΓେ͖ͳαΠζ͕ࢦఆ͞Εͨͱ͖ʹ࢖ΘΕΔ
  113. contentHuggingPriorityͷ஋ΛνΣοΫ   ੍໿ͷ༏ઌ౓ΛΘ͟ͱ௿͘͠ͳ͍ݶΓ͸ɺ ίϯςϯπͷେ͖͞ʹ͔͔ΘΒ੍ͣ໿͕༏ઌ͞ΕΔ →Button͕৳ͼͯ͠·ͬͨ

  114. ղܾ͢Δʹ͸   TextField͸Ͱ͖Δ͚ͩ޿͘औΓ͍͕ͨ Button͸࠷௿ݶͷେ͖͞Ͱ͍͍ͷͰ ButtonͷcontentHuggingPriorityΛ্͛Δ

  115. ׬੒

  116. CASE 14. contentCompressionResistancePriority Λௐ੔͢Δ αϯϓϧίʔυ 1SJPSJUZ7JFXΑΓɻ

  117. ࡞Γ͍ͨϨΠΞ΢τ  iPhone 8 Plus iPhoneSE  ෯͕଍Γͳ͘ͳͬͨΒͬͪ͜ ͷϥϕϧΛলུͯ͠ௐઅ ࠷௿ͷԣ෯͸֬อ

  118. iPhoneSE Կ͔͕͓͔͍͠ ͬͪ͜ͷϥϕϧ͕ লུ͞Εͯ͠·͍ͬͯΔ iPhone 8 Plus

  119. Կ͔͕͓͔͍͠ 1SJPSJUZӠʑ ݴΘΕͯΔ

  120. contentCompressionResistancePriorityͱ͸ • খ͘͞ͳΓʹ͘͞ / ѹॖ఍߅༏ઌ౓ • ͜ͷ஋͕খ͍͞ͱଞͷ੍໿ʹӨڹ͞Εͯখ͘͞ͳΓ΍͘͢ͳΔ • ݻ༗αΠζΑΓখ͍͞αΠζ͕ࢦఆ͞Εͨͱ͖ʹ࢖ΘΕΔ

  121. contentCompressionResistancePriorityͷ஋ΛνΣοΫ   ʮYeahʯϥϕϧͷํΛ༏ઌతʹॖΊͯ΄͍͠ͷͰɺ ʮYeahʯϥϕϧͷcontentCompressionResistancePriorityͷ ༏ઌ౓ΛԼ͛Δͱྑͦ͞͏ 

  122. ׬੒

  123. LLDB࢖͏ܥ

  124. CASE 15. ͍Ζ͍Ζ࢖ͬͯΈΔ αϯϓϧίʔυ &RVBM8JEUI7JFXΑΓɻ

  125. ࡞Γ͍ͨϨΠΞ΢τ ֤7JFXͷ ԣ෯͸ ֤7JFXͷؒʹಁ໌ͳ 4QBDFS7JFXΛ഑ஔ iPhone 8 PlusͩͬͨΒ໰୊ͳ͔ͬͨ

  126. Demo ͜ͷষͷ͔͜͜Βઌ͸ɺ σϞͷεΫγϣΛషΓ෇͚ͨ΋ͷͰ͢

  127. Կ͔͕͓͔͍͠ Ұݟେৎ෉ͦ͏͚ͩͲ iPhone SEαΠζͩͱ μϝͩͬͨ ʘ8BSOJOHʗ

  128. Ͳ͕͓͔͍͜͠ʁ ਫฏํ޲ͷ੍໿͕͓͔͍͜͠ͱ͕Θ͔Δ XJEUI MFBEJOH.BSHJO USBJMJOH.BSHJO

  129. ͔ͯͲΕ͕ͲͷViewʁ identifier෇͚Δͷ໘౗ͩ͠ ผͷํ๏Ͱ۠ผ͠Α͏

  130. ํ๏1ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̍ ·ͣ͸ ϏϡʔσόοΨʔΛ ىಈͯ͠LLDB͕ ࢖͑Δঢ়ଶʹ͢Δ

  131. ํ๏1ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̍ lWJFXXJEUIΛ յͨͥ͠z յ͞ΕͨWJFXΛ ൑ผ͢ΔͨΊʹ ৭Λ෇͚ͯΈΑ͏

  132. ํ๏1ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̍ ඞཁͳϑϨʔϜ ϫʔΫΛJNQPSU --%#ͷݴޠΛ 4XJGUʹ

  133. ํ๏1ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̍ VOTBGF#JU$BTUΛ ࢖ͬͯϙΠϯλ͔Β ΦϒδΣΫτΛऔಘ ΦϒδΣΫτԽ͍ͨ͠ ΋ͷͷΞυϨεΛࢦఆ

  134. ํ๏1ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̍ ΦϒδΣΫτԽͨ͠ WJFXͷഎܠ৭Λ੺ʹ

  135. ํ๏1ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̍ ը໘ΛϦϑϨογϡͯ͠ มߋΛ൓ө

  136. ํ๏1ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̍ ͜ͷWJFXͷXJEUIͷ ੍໿͕յΕͨΒ͍͠ʂ

  137. ํ๏̎ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̎ ΦϒδΣΫτԽ͍ͨ͠ ΋ͷͷΞυϨεΛࢦఆ

  138. ํ๏̎ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̎ WJFXͷഎܠ৭Λ੺ʹ

  139. ํ๏̎ɿLLDB্ͰΦϒδΣΫτΛૢ࡞͢Δ̎ ͜ͷWJFXͷXJEUIͷ ੍໿͕յΕͨΒ͍͠ʂ σόοάऴྃ

  140. ํ๏̏ɿtext filterΛ࢖͏ ΞυϨεΛUFYUpMUFSʹ ίϐϖʂ ֘౰͢ΔΦϒδΣΫτʹ ৭͕͍ͭͨʂ

  141. ԫ৭viewͷwidthΛݟͯΈΔͱ… ͔֬ʹXJEUIͷ ੍໿͕յΕ͍ͯΔ

  142. ༧૝͍ͯͨ͠ϨΠΞ΢τ SEͷԣ෯͸320ɺ֤Viewͷ෯͕100Ͱ leadingMarginɺtrailingMargin͕0ʹͳͬͯΔ͔Βɺ ViewؒͷSpacerView͕ॖ·Ε͹ͪΌΜͱऩ·ΔͷͰ͸ʁʁ

  143. ͯΏ͏͔… ͳΜͰleadingʹ伱͕ؒ Ͱ͖ͯΔΜͩΖ͏ʁʁ →ϏϡʔσόοΨʔͰ΋ ɹ֬ೝͯ͠ΈΑ͏

  144. Storyboard্Ͱ੍໿Λ֬ೝ͢Δํ๏̍ TIPX$POTUSBJOUT ੍໿ͷ಺༰

  145. Storyboard্Ͱ੍໿Λ֬ೝ͢Δํ๏̎ ੍໿ΛӈΫϦοΫͰ ಺༰Λग़ྗ

  146. superview͕͓͔͍͠ʁʁ ಛʹ໰୊ͳͦ͞͏

  147. Կ͕͓͔͍͠Μͩʁʁ ͋ΕɺtrailingMarginͬͯ΋͔ͯ͠͠…ʁ

  148. 3FMBUJWF UPNBSHJO ʹνΣοΫ͕ೖ͍ͬͯΔ ͭ·Γ QU͕ܭࢉʹೖ͍ͬͯΔ Կ͕͓͔͍͠Μͩʁʁ

  149. Relative to marginͷνΣοΫΛ֎ͯ͠… 3FMBUJWFUP NBSHJO ͷνΣοΫΛ֎ͯ͠ DPOTUBOUΛʹ

  150. ׬੒ʂ ղܾ

  151. CASE 16. facebook / chiselΛ࢖͏

  152. facebook / chiselͱ͸ • LLDBΛ࢖ͬͨσόοάΛศརʹͯ͘͠ΕΔίϚϯυ܈ • HomebrewͰΠϯετʔϧͰ͖Δ • ίϚϯυΛΧελϚΠζ͢Δ͜ͱ΋Մೳ

  153. Πϯετʔϧํ๏ $ brew update $ brew install chisel $ echo

    "command script import /usr/local/Cellar/chisel/ 1.8.0/libexec/fblldb.py" >> ~/.lldbinit-Xcode ※ύε͸దٓมߋ͍ͯͩ͘͠͞ɻ Xcode࠶ىಈ
  154. ࢖͍ํ (lldb) help Λଧͯ͹ίϚϯυͷҰཡ͕ग़ͯ͘ΔͷͰͦΕʹैͬͯ࢖͍·͢ɻ ΋ͪΖΜࠓ·Ͱ࢖͍ͬͯͨίϚϯυ΋࢖͑·͢ɻ ͜͜Ͱ͸͍͔ͭ͘ϐοΫΞοϓͯ͠঺հ͠·͢ɻ

  155. pviews • viewͷ֊૚ߏ଄Λදࣔͯ͘͠ΕΔ • Ҿ਺ʹviewͷΞυϨεΛࢦఆ͢ΔͱͦͷviewҎԼͷ֊૚ߏ଄Λ ɹදࣔͯ͘͠ΕΔ • recursiveDescriptionͷ݁ՌΛϑΟϧλϦϯάͨ͠΋ͷ

  156. pviews ֘౰ͷWJFX্ʹ ͭͷWJFX͕ ͋Δ͜ͱ͕Θ͔Δ

  157. border • Ϗϡʔɺ΋͘͠͸ϨΠϠʔʹରͯ͠࿮ઢΛදࣔͯ͘͠ΕΔ • ઌͷ৭΍෯͸ΦϓγϣϯͰࢦఆ͢Δ͜ͱ͕Ͱ͖Δ • Կ֊૚Լͷview·Ͱ࿮ઢΛ෇͚Δ͔Λ-d(depth)Ͱࢦఆ͢Δ ɹ͜ͱ͕Ͱ͖Δ • ৭͕෇͍͓ͯΒͣڥ໨͕Θ͔Γʹ͍͘viewΛ֬ೝ͢Δ࣌ͳͲʹ

    ɹ࢖͑ͦ͏
  158. border EFQUIͱΞυϨεΛ ࢦఆ

  159. border ϏϡʔσόοΨʔ ղআޙͷ༷ࢠ ࠶౓ ϏϡʔσόοΨʔ ىಈ

  160. ղܾͷࢳޱΛݟ͚ͭΔίπ

  161. ݻఆ௕Ͱͳ͍ͱ͜ΖΛνΣοΫ͢Δ • શ෦ݻఆ௕Ͱࢦఆ͍ͯ͠Ε͹ϨΠΞ΢τ͸่Εͳ͍͸ͣ • ਖ਼͘͠Մมʹͳ͍ͬͯΔ͔νΣοΫ͠Α͏

  162. ౔୆ʹͳΔviewͷαΠζ͕ద੾͔֬ೝ͢Δ • cellͱ͔xib͸ߴ͕ࣗ͞༝ʹม͑ΒΕΔ͕ɺ͋·Γʹ΋ ɹϑϦʔμϜͩͱதͷཁૉͷ੍໿ͱטΈ߹Θͳͯ͘ΤϥʔʹͳΔ • ౔୆ͷview͸ϓϨϏϡʔͷ࿮Ͱ͸ͳ͘σβΠϯͷҰ෦ͳͷͰ ɹ͜͜΋ͪΌΜͱέΞ͢Δ

  163. ༏ઌ౓Λઃఆͯ͠ͳ͍͔֬ೝ͢Δ • ༏ઌ౓͕ग़ͯ͘Δͱͻͱ໨Ͱ͸੍໿͕ਖ਼͍͠ͷ͔ؒҧͬͯΔͷ͔ ɹ͕Θ͔Γʹ͍͘ • Storyboard্ͰҰ౓༏ઌ౓ΛΘ͟ͱͣΒͯ͠ௐઅ͠ɺ ɹऴΘͬͨΒݩʹ໭ͨ͠Γͯ͠΋͍͍͔΋

  164. ෳ਺ͷ୺຤Ͱ֬ೝ͢Δ • Auto LayoutͰ࡞͍ͬͯΔ ≠ શͯͷαΠζͰਖ਼͍͠ • ϓϨϏϡʔ୺຤Λ੾Γସ͑Α͏

  165. ੍໿่͕Ε͍ͯΔ࣠Λ೺Ѳ͢Δ • ଟ͘ͷϫʔχϯάʹک͑ͣɺํ޲ΛݟۃΊΑ͏ • ͕࣠Θ͔Ε͹ॱʹݟͯղܾ͠΍͍͢ • ྆࣠ؒҧͬͯͨΒAspect Ratio΍Multiplierɺ ɹEqual Width

    / HeightΛٙ͏
  166. ຊ౰ʹඞཁͳ੍໿Λߟ͑Δ • σβΠϯΛ౉͞Εͨ࣌ʹɺͲΕ͕୺຤αΠζʹґଘ͠ͳ͍ ɹ਺஋ͳͷ͔Λߟ͑Δ • ඞཁͰ͋Ε͹σβΠφʔʹ֬ೝ͢Δ

  167. Ұ͔Β૊Έ௚͢ • ࠷ऴखஈ • طଘͷσβΠϯͷมߋ͸ࢥΘ͵͏͔ͬΓΛট͘ • ৔߹ʹΑͬͯ͸ࣗ෼Ͱશ෦૊Έ௚ͨ͠ํ͕ૣ͍͔΋͠Εͳ͍

  168. transformΛ࢖͍ͬͯͳ͍͔֬ೝ͢Δ • transformͰͷม׵͸Auto Layoutͷܭࢉʹ͸Ұ੾Өڹ͠ͳ͍ • Auto LayoutͰ͸ະม׵࣌ͷۣܗ͕ߟྀ͞ΕΔ

  169. ඳըํ๏͕ಛघͰͳ͍͔֬ೝ͢Δ • جຊతʹ͸view͸ڥք಺ʹ഑ஔ͞ΕΔ͕ɺάϥϑΟοΫ ɹΤϯδϯ͸ͦͷݶΓͰ͸ͳ͍ • ඳը͕ಛघͳ৔߹ɺϑϨʔϜͱ͸ҟͳΔੇ๏ͷྖҬʹඳը͢Δ ɹ͜ͱ͕͋Δ • viewͷclipsToBoundsΛtrueʹ͢Δ͔ϑϨʔϜͷੇ๏Λม͑Ε͹ ɹൃݟͰ͖Δ

  170. ·ͱΊ

  171. • Auto Layout่ΕͷݪҼΛ୳Δํ๏͸͍ͭ͘΋͋Δ • ʮ঱ঢ়ʯʹ߹ͬͨਖ਼͍͠ʮ਍࡯ʯ͕Ͱ͖Ε͹΋͏ා͘ͳ͍ • ࠓ೔঺հͨ͠಺༰͸໌೔͔Β࢖͑ΔͷͰͥͻ࢖ͬͯͶ

  172. None
  173. None
  174. ؔ࿈ࢿྉ

  175. • σόοάͷͨΊʹView֊૚Λ೺Ѳ͢Δ • https://qiita.com/akatsuki174/items/ 45d4bd7cb150defbf116 • AutoLayoutͷσόοάΛ͢Δʢ1ʣ • https://qiita.com/akatsuki174/items/6935bb6ff64f4df51c5a •

    Debugging your layout ([WWDC2015] Mysteries of Auto Layout, Part 2ΑΓ) • https://qiita.com/akatsuki174/items/ 66c6a92ab52b458f5414
  176. • Auto Layoutͷϫʔχϯάղಡʹ͸ʮWTF?ʯ͕ศར • https://qiita.com/akatsuki174/items/ ccf394c03677ac62191e • Auto Layoutͷσόοάʹ໾ཱͭϝιου/ϓϩύςΟू •

    https://qiita.com/akatsuki174/items/ 550f885c002fb881674c
  177. ࢀরจݙ

  178. • Mysteries of Auto Layout, Part 2 (WWDC 2015) •

    https://developer.apple.com/videos/play/wwdc2015/219/ • Α͘Θ͔ΔAuto Layout • גࣜձࣾϦοΫςϨίϜ. ઒ᬒ ༤հ ஶ. ॴ ༑ଠ ؂म.
  179. એ఻

  180. ϦϞʔτ࿮΋ ͋ΔΑʂ τʔΫ΍͓୊ Ԡืͯ͠ΔΑʂ

  181. ͝ਗ਼ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ ʘ౤ථΑΖ͘͠ʗ