ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [iOS] Container View Controller ๋ž€?
    iOS/๐Ÿค– App 2021. 7. 26. 18:09

    1์ฐจ ์ˆ˜์ •: 21.09.30

     

    ์•ˆ๋…•ํ•˜์„ธ์š” ๐Ÿถ

    ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ViewController ์˜ ์ข…๋ฅ˜ ์ค‘ ํ•˜๋‚˜์ธ

    Container View Controller ์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    ๊ทธ๋Ÿผ ์‹œ์ž‘ํ• ๊ฒŒ์š”๐Ÿ”ฅ


     

    ์šฐ์„  View Controller ๋ฅผ ์—ญํ• ๋กœ ๊ตฌ๋ถ„ํ•˜์ž๋ฉด ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€ ์ข…๋ฅ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค!

     

    ์ฒซ๋ฒˆ์งธ๋Š” Content View Controller ๋กœ์„œ,

    ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์—๊ฒŒ ๊ธฐ๋Œ€ํ•˜๋Š” ์—ญํ• ( ์•ฑ ๋‚ด ๋ฐ์ดํ„ฐ๋ฅผ ํ™”๋ฉด์— ๋ณด์—ฌ์ฃผ๋Š” ๋“ฑ) ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์ž…๋‹ˆ๋‹ค.

    ์ผ๋ฐ˜์ ์œผ๋กœ UIViewController ๋ฅผ ์ง์ ‘ ์„œ๋ธŒํด๋ž˜์‹ฑํ•˜์—ฌ ์ปค์Šคํ…€ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์ž…๋‹ˆ๋‹ค.

    class MyHomeViewController: UiViewController { ... }

     

     

    ๋‘๋ฒˆ์งธ๋Š” ์ด๋ฒˆ ์‹œ๊ฐ„์— ๋‹ค๋ฃฐ Container View Controller ๋กœ์„œ,

    ์—ฌ๋Ÿฌ ์š”์†Œ๋ฅผ ์กฐํ•ฉํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ( composite interface )

     

    ๋ณดํ†ต ์ง์ ‘ ๋ฌด์–ธ๊ฐ€๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์—ญํ• ์€ ์—†์œผ๋ฉฐ,

    ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ ๊ฐ„์— ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ํ˜•์„ฑํ•˜์—ฌ ์ž์‹ ๋งŒ์˜ ๋ฐฉ์‹์œผ๋กœ ์ž์‹์„ ๊ด€๋ฆฌํ•˜๋Š” ์—ญํ• ์„ ๋งก๋Š” ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ ์ž…๋‹ˆ๋‹ค.

    ๊ฐ„๋‹จํ•˜๊ฒŒ ์ƒ๊ฐํ•ด๋ณด๋ฉด, Container View Controller ๋“ค์ด Content View Controller ๋“ค์„ ๊ด€๋ฆฌํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋˜๊ฒ ๋„ค์š”!

     

    ๊ทธ๋Ÿฐ๋ฐ ์ด๋ฏธ UIKit ์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” System Container View Controller ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    UITabBarController, UINavigationController, UIPageViewController ๋“ฑ์ด ๊ทธ๊ฒƒ๋“ค์ž…๋‹ˆ๋‹ค.

     

    container view controller ๋ผ๊ณ  ๋ช…์‹œ์ ์œผ๋กœ ์ ํ˜€ ์žˆ๋‹ค.

     

    ์ด ๋•Œ Contianer View Controller ๋“ค์˜ ํŠน์ง•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

    ์ž์‹ View Controller ๋“ค์˜ ์ฐธ์กฐ๋ฅผ ๊ฐ€์ง€๊ณ  ๊ด€๋ฆฌํ•œ๋‹ค๋Š” ๊ฒƒ์ธ๋ฐ์š”.

    ๋ณดํ†ต ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ์ž์‹ ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ณ , ์ž์‹ ๊ด€๊ณ„๋ฅผ ์ƒˆ๋กœ ์„ค์ •ํ•ด ์ค„์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

     

     

    ๊ทธ๋Ÿฐ๋ฐ ์™œ ๊ตณ์ด ์ด๋Ÿฐ ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ด€๋ฆฌํ•ด์ฃผ๋Š”์ง€์— ๋Œ€ํ•œ ์˜๋ฌธ์ด ์ƒ๊น๋‹ˆ๋‹ค.

    ์ปจํ…Œ์ด๋„ˆ๋Š” ์™œ ํ•„์š”ํ•œ ๊ฑธ๊นŒ์š”?


     

     

    Container View Controller ๋Š” ์™œ ํ•„์š”ํ• ๊นŒ?

     

    ๐ŸŸข  Navigation ๋กœ์ง (๋ผ์šฐํŒ…) ์„ ๋ถ„๋ฆฌํ•˜์—ฌ ๋‹จ์ผ ์ฑ…์ž„์›์น™์„ ์ง€ํ‚ค๋ ค๋Š” ์‹œ๋„์ด๋‹ค.

    " promote better encapsulation by separating out your content

    from how you display that content onscreen"

     

    MVC ํŒจํ„ด์„ ๊ณต๋ถ€ํ•  ๋•Œ

    ๋„ˆ๋ฌด๋„ˆ๋ฌด ๋งŽ์ด ๋“ค์–ด๋ดค์„ Massive View Cotroller ์— ๋Œ€ํ•ด ์•„์‹ค๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

     

    ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์€ ์—ญํ• (์ฑ…์ž„)์„ ํ•˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์ธ๋ฐ, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ํ•œ๋ฒˆ ๋ณผ๊ฒŒ์š”.

     

      func showChildVC() {
        // ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•œ๋‹ค
        let childVC = ChildViewController()
    	
        // ์ง์ ‘ ์˜์กด์„ฑ ์ฃผ์ž…๋„ ํ•ด์ค€๋‹ค
        childVC.someDedendency = SomeDependency()
    	
        // ์ง์ ‘ ํ™”๋ฉด์— ํ‘œ์‹œ๋„ ํ•ด์ค€๋‹ค
        present(childVC, animated: true, completion: nil)
      }

     

    ์œ„ ์ฝ”๋“œ๋Š” ์•„๋ฌด ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์ด ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ๋„ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋Š” ๋งŽ์€ ์ฑ…์ž„์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

     

    1. ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜์—ฌ ์ƒ๋ช…์ฃผ๊ธฐ์— ๊ด€๋ คํ•˜๊ณ 

    2. ์˜์กด์„ฑ์„ ์ฃผ์ž…ํ•ด์ฃผ๊ณ 

    3. ํ™”๋ฉด์— ๋„์›Œ์ฃผ๋Š” ์—ญํ• ๊นŒ์ง€

     

    ์ฑ…์ž„์ด ๋งŽ์œผ๋ฉด ์œ ์ง€๋ณด์ˆ˜์™€ ํ…Œ์ŠคํŠธ๊ฐ€ ํž˜๋“ค์–ด์ง‘๋‹ˆ๋‹ค.

     

    ๋”ฐ๋ผ์„œ ํ™”๋ฉด์— ํ‘œ์‹œํ•ด์ฃผ๋Š” ์ฑ…์ž„์„ ๋‹ค๋ฅธ ๊ฐ์ฒด๋กœ ๋ถ„๋ฆฌํ•ด ๋‚ธ ๊ฒƒ์ด ์ปจํ…Œ์ด๋„ˆ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์ž…๋‹ˆ๋‹ค.

     

     

    ์‹œ์Šคํ…œ ์ปจํ…Œ์ด๋„ˆ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ ์ค‘ ํ•˜๋‚˜์ธ

     

    Navigation Controller ๋ฅผ ์˜ˆ๋กœ ๋“ค๋ฉด

     

    ์ปจํ…Œ์ด๋„ˆ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์ž์‹ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์— ๋Œ€ํ•œ ํ™”๋ฉด ์ „ํ™˜์„ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ํ•˜๋Š”์ง€ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

       @IBAction func pushSecond(_ sender: Any) {
       
        /* ์—ฌ๊ธฐ๋Š” secondVC ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ฝ”๋“œ๊ฐ€ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค */
        
        // ์ง์ ‘ ๋‹ค์Œ ํ™”๋ฉด์„ ํ‘œ์‹œํ•˜์ง€ ์•Š๊ณ , navigationController ์— ์˜์กดํ•œ๋‹ค
        navigationController?.pushViewController(secondVC, animated: true)
       }

     

    present(_:animated:completion:) ๊ณผ ๊ฐ™์€ ํ™”๋ฉด ์ฒ˜๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ์ง์ ‘ ํ˜ธ์ถœํ•˜์ง€ ์•Š๊ณ ,

    navigationController ์—๊ฒŒ ํ™”๋ฉด์— ํ‘œ์‹œํ•  VC๋ฅผ ์ „๋‹ฌํ•˜์—ฌ ํŠธ๋žœ์ง€์…˜๊ณผ ํ™”๋ฉด ํ‘œ์‹œ๋ฅผ ๋งก๊ธฐ๊ณ  (์˜์กดํ•˜๊ณ ) ์žˆ์Šต๋‹ˆ๋‹ค.

     

    pushViewController(_:animated:) ๋ณด๋‹ค๋„ ์ €๋Š” show(_:sender:) ๋ฅผ ์ข‹์•„ํ•˜๋Š”๋ฐ์š”...

    ์ข€ ๋” ์ถ”์ƒํ™”๋œ ๋ฉ”์„œ๋“œ๋ผ๊ณ  ๋ณด์‹œ๋ฉด ๋˜๊ณ , ์ž์„ธํ•œ ๋™์ž‘์€ ๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

     

    ์•„๋ฌดํŠผ ์ €๋Š” ์ €๋Ÿฐ ๋ฐฉ์‹์ด ์™„๋ฒฝํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค.

    ์—ฌ์ „ํžˆ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜๊ณ , ์˜์กด์„ฑ ์ฃผ์ž…๋„ ํ•ด์ฃผ๋Š” ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ•˜๋‹ˆ๊นŒ์š”.

     

    ๐ŸŸฃ ๋ทฐ ์ž์ฒด์˜ ๊ตฌ์—ญ์„ ๋ถ„๋ฆฌํ•˜์—ฌ ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์šฉ์ดํ•ด์ง„๋‹ค.

     

    ์ปจํ…Œ์ด๋„ˆ ๋ทฐ์ปจ์˜ ๋ฃจํŠธ ๋ทฐ๋ฅผ  ๋ช‡ ๊ฐœ์˜ ๊ตฌ์—ญ์œผ๋กœ ๋‚˜๋ˆ„์–ด

    ๊ตฌ์—ญ๋ณ„๋กœ ํŠน์„ฑ์— ๋งž๊ฒŒ ๊ฐ๊ฐ์˜ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋‘๊ณ  ๋”ฐ๋กœ ๊ด€๋ฆฌํ•˜๋ฉด

    ์ฑ…์ž„๋„ ๋ถ„๋ฆฌ๋˜๊ณ  ์œ ์ง€๋ณด์ˆ˜๋„ ์ข€ ๋” ์‰ฌ์›Œ ์งˆ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

     

    ์œ„์˜ ์ด๋ฏธ์ง€๋Š” UIKit ์ด ์ œ๊ณตํ•˜๋Š” UISplitViewController ๋กœ์„œ

    ๋ฃจํŠธ ๋ทฐ๋ฅผ ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ ๋‘๊ฐœ์˜ ๊ตฌ์—ญ์œผ๋กœ ๋‚˜๋ˆ„์–ด ๊ตฌ์—ญ๋ณ„๋กœ

    ๋‹ค๋ฅธ ์ฑ…์ž„์„ ๊ฐ€์ง€๋Š” ์ž์‹ ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ๋“ค์„ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

     

    ์•„์ดํŒจ๋“œ์—์„œ ์‰ฝ๊ฒŒ ๋ณผ ์ˆ˜์žˆ๋Š” UI ๊ตฌ์„ฑ์ธ๋ฐ, ๋ณดํ†ต ์™ผ์ชฝ์— Table VC, ์˜ค๋ฅธ์ชฝ์— Content VC ๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ ์ž์ฃผ ๋ณด์…จ์ฃ ?

     

     


     

     

    UIContainerViewController ๊ฐ€ ๊ณต์‹๋ฌธ์„œ์— ์—†์–ด์š” ๐Ÿค”

     

    ์• ํ”Œ ๊ณต์‹๋ฌธ์„œ์—์„œ ์ฐพ์•„๋ณด๋ฉด ์•„์‹œ๊ฒ ์ง€๋งŒ, UIContainerViewController ์™€ ๊ฐ™์€ ํด๋ž˜์Šค๋Š” ์—†์Šต๋‹ˆ๋‹ค.

     

    Container View Controller ๋Š” ํ•˜๋‚˜์˜ ๊ฐœ๋…์ด๋ฉฐ, ๊ธฐ์กด์— ์กด์žฌํ•˜๋Š” ํด๋ž˜์Šค๋“ค์„ ์ด์šฉํ•ด์„œ ์ปค์Šคํ…€ ๊ตฌํ˜„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

     

    UIViewController ๋ฅผ ์„œ๋ธŒํด๋ž˜์‹ฑํ•˜์—ฌ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    " A custom UIViewController subclass can also act as a container view controller. "

     

    ๋งŒ์•ฝ ์ปค์Šคํ…€ ํ•˜์ง€ ์•Š๊ณ  ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด,

    UINavigationController, UITabBarControler ์™€ ๊ฐ™์ด System Container View Controller ๋ฅผ ์‚ฌ์šฉํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

     

    ์ด ํด๋ž˜์Šค๋“ค์€ ํด๋ž˜์Šค๋งŒ์˜ ๋ฐฉ์‹๋Œ€๋กœ ํ•˜์œ„ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋“ค์„ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

     

    ๊ฐ ์ปจํ…Œ์ด๋„ˆ VC ๋“ค์˜ ํŠน์„ฑ๋“ค์„ ์ดํ•ดํ•˜๊ณ  ์šฉ๋„์— ๋งž๊ฒŒ ์‚ฌ์šฉํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

    ๋Œ€ํ‘œ์ ์ธ ์‹œ์Šคํ…œ ์ปจํ…Œ์ด๋„ˆ ๋ทฐ์ปจํŠธ๋กค๋Ÿฌ์ธ ๋„ค๋น„๊ฒŒ์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ์˜ ์˜ˆ์‹œ ( ๊ธฐ๋ณธ์‹œ๊ณ„ ์•ฑ )

     

     

    ์ปค์Šคํ…€ ์ปจํ…Œ์ด๋„ˆ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์€ ์ปค์Šคํ…€ํ•˜๋Š” ์‚ฌ๋žŒ์˜ ๋ชซ์ž…๋‹ˆ๋‹ค.

     

    ์˜ˆ๋ฅผ ๋“ค์–ด ์ž์‹ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ํ™”๋ฉด์„ ๊ทธ๋Œ€๋กœ ๋ณด์—ฌ์ค„ ์ˆ˜๋„ ์žˆ๊ณ ,

    ์›ํ•˜๋Š” ๋ ˆ์ด์•„์›ƒ์„ ์„ค์ •ํ•ด์„œ ๋ณด์—ฌ์ค„์ˆ˜๋„ ์žˆ๊ณ  ( ์˜ˆ๋ฅผ ๋“ค์–ด ํ™”๋ฉด ๋ฐ˜๋ฐ˜)

    ํ˜น์€ ๋ฏธ๋ฆฌ ๊ตฌํ˜„๋œ container view ๋ฅผ ์‚ฌ์šฉํ•ด๋ณผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.


     

    Container View ๋Š” ๋˜ ๋ญ”๊ฐ€์š”

     

    "  A container view is a proxy view that stands in for the content of a child view controller. "

     

    ์ปจํ…Œ์ด๋„ˆ ๋ทฐ๋Š” ์ธํ„ฐํŽ˜์ด์Šค ๋นŒ๋”์—์„œ๋งŒ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋Š” ์ผ์ข…์˜ ํ”„๋ก์‹œ ๋ทฐ์ž…๋‹ˆ๋‹ค.

    ์ปจํ…Œ์ด๋„ˆ ๋ทฐ๋Š” ์˜ค๋ธŒ์ ํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ๋งŒ ์ฐพ์•„์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ์•„๋ž˜ ์‚ฌ์ง„์„ ๋ณด์‹œ๋ฉด

    ์™ผ์ชฝ์˜ ์”ฌ์— ์ถ”๊ฐ€ํ•œ Container View ๋Š”  

    ๊ธฐ์กด VC ์™€ ์ƒˆ๋กœ์šด ์˜ค๋ฅธ์ชฝ์˜ VC ๋กœ ์ด์–ด์ง„ Embed Segue ๋กœ์˜ ์—ฐ๊ฒฐ์„ ํ†ตํ•˜์—ฌ ์ปจํ…์ธ ๋ฅผ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

    ๊ทธ๋ž˜์„œ ๋งŒ์•ฝ ์™ผ์ชฝ VC ์ฐธ์กฐ ์–ป์œผ๋ ค๋ฉด prepare(forSegue:~) ์—์„œ ์ „๋‹ฌํ•ด์•ผํ•จ

     

    ์ฆ‰ ์™ผ์ชฝ์˜ Container View ์˜์—ญ์— ์˜ค๋ฅธ์ชฝ์˜ VC ์˜ ๋ทฐ ๊ณ„์ธต์„ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ์ด์ฃ !

     

    ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์™€ ์—ฐ๊ฒฐ๋œ Embed Segue ์„ ๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

     

    ์–˜๋Š” ๊ณต์‹๋ฌธ์„œ๋„ ์—†์Œ;;;;;;;;;;

    Container View ๋Š” ๊ณต์‹๋ฌธ์„œ๊ฐ€ ์—†๋‹ค

     


     

    Custom Container View Controller ๊ตฌํ˜„

     

    ๊ธฐ๋ณธ์ ์ธ ์ปจํ…Œ์ด๋„ˆ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋™์ž‘์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    ์ฃผ์„์œผ๋กœ ์„ค๋ช…์„ ์ฒจ๋ถ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

    // ํ˜„์žฌ์˜ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์— ์ž์‹ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ์ฝ”๋“œ
    let storyboard = UIStoryboard(name: "Main", bundle: .main)
    if let viewController = storyboard.instantiateViewController(identifier: "imageViewController")
                                        as? ImageViewController {
    
       // ํ•ต์‹ฌ ๋ฉ”์†Œ๋“œ๋กœ์„œ, ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์— ๋ถ€๋ชจ-์ž์‹ ๊ด€๊ณ„๋ฅผ ํ˜•์„ฑํ•œ๋‹ค
       addChild(viewController)
       
       // ์ž์‹ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ฃจํŠธ ๋ทฐ๋ฅผ ํ˜„์žฌ ๋ทฐ์˜ ๋ทฐ ๊ณ„์ธต์— ์ถ”๊ฐ€ํ•˜๋Š” ์ฝ”๋“œ
       view.addSubview(viewController.view)
                
       // ์ œ์•ฝ ์ƒ์„ฑ
       onscreenConstraints = configureConstraintsForContainedView(containedView: viewController.view,
                                 stage: .onscreen)
       NSLayoutConstraint.activate(onscreenConstraints)
         
       // ํ™”๋ฉด ์ „ํ™˜์ด ์™„๋ฃŒ๋˜์—ˆ๋‹ค๋ฉด ์ž์‹ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์•Œ๋ ค์ค€๋‹ค.
       viewController.didMove(toParent: self)
    }

    ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜ ์ฒจ๋ถ€๋œ ๋งํฌ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด ๋ฉ๋‹ˆ๋‹ค


     

     

     

    ๋!


    ์ฐธ๊ณ ์ž๋ฃŒ: https://developer.apple.com/documentation/uikit/view_controllers/creating_a_custom_container_view_controller/

     

    ๋Œ“๊ธ€

์–ด์ œ๋ณด๋‹ค ๋ฐœ์ „ํ•œ ๋‚˜