Swift

Swift - viewDidLayoutSubviews()

iosos 2024. 10. 20. 17:52

๐Ÿ“‘ ํ•™์Šต ๋‚ด์šฉ

  • ๋ทฐ๊ฐ€ ํ•˜์œ„ ๋ทฐ์˜ ๋ ˆ์ด์•„์›ƒ์„ ์™„๋ฃŒํ•˜๋ฉด ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์—๊ฒŒ ์•Œ๋ฆฌ๋Š” ๋ฉ”์„œ๋“œ
  • ๋ทฐ์™€ ์„œ๋ธŒ๋ทฐ๋“ค์˜ ๋ ˆ์ด์•„์›ƒ์ด ๋ชจ๋‘ ์ •ํ•ด์ง„ ํ›„ ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์„œ๋“œ
    • ๋”ฐ๋ผ์„œ, ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋Š” ํ•˜์œ„ ๋ทฐ๋ฅผ ๋ ˆ์ด์•„์›ƒํ•œ ํ›„ ๋ณ€๊ฒฝ ํ•˜๊ธฐ ์œ„ํ•ด ์ด ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•จ
  • viewDidLayoutSubviews ๋Š” ๋ทฐ๊ฐ€ ์ƒ์„ฑ๋˜๊ณ  ํ™”๋ฉด์— ๋ณด์ด๊ธฐ ์ง์ „ ์ƒํƒœ๋กœ ์ตœ์ดˆ๋กœ ๋ทฐ๋“ค์˜ ํฌ๊ธฐ๋‚˜ ์œ„์น˜๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋Š” ์‹œ์ ์ž„
    • ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ UIView์˜ ๋ ˆ์ด์•„์›ƒ์„ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์„ ๋•Œ viewDidLoad()์—์„œ ๋ณ€๊ฒฝํ•˜๊ฒŒ ๋˜๋ฉด ์ •์ƒ์ ์œผ๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Œ (์•„์ง ๋ ˆ์ด์•„์›ƒ์ด ์žกํžˆ์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ)
    • ๋”ฐ๋ผ์„œ viewDidLayoutSubviews() ์—์„œ ๋ณ€๊ฒฝํ•ด์ค˜์•ผ ํ•จ
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        // ๋ ˆ์ด์•„์›ƒ ๋ณ€๊ฒฝ ์ฝ”๋“œ
        if !isInitLayout {
            self.updateUnderLineView(segment: homeView.segmentedControl, isInit : true)
            isInitLayout = true
        }
    }

๐Ÿ“š ์ฐธ๊ณ  ์ž๋ฃŒ