์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[UIKit] ํ•˜ํ”„๋ชจ๋‹ฌ ๊ตฌํ˜„(Scrollable Bottom Sheet) - SheetPresentationController

๐ŸŽ iOS/UIKit

by AHN.Jihyeon 2024. 7. 3. 17:46

๋ณธ๋ฌธ


์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์™ผ์ชฝ์˜ ๊ฒ€์€์ƒ‰ ํ™”๋ฉด ์ฒ˜๋Ÿผ ๋œฌ๋‹ค. 

์™œ ๋ชจ๋‹ฌ์ด ์•ˆ ๋œจ๊ณ  ๋ฒ„ํŠผ์ด ๋œจ๋Š”์ง€ ์˜๋ฌธ์ด์—ˆ๋‹ค. 

๋ฐฐ๊ฒฝ์„ ํ™”์ดํŠธ๋กœ ์„ค์ •ํ•ด๋‘๊ณ  ๋ณด๋‹ˆ ๋ชจ๋‹ฌ์€ ์˜ฌ๋ผ ์™”์œผ๋‚˜

๋ฐฐ๊ฒฝ์ด ๊ฒ€์€์ƒ‰์ด์–ด์„œ ๋ฒ„ํŠผ๋งŒ ์˜ฌ๋ผ์˜จ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์˜€๋‹ค. 

 

๊ทธ๋ฆฌ๊ณ  ์—ฌ๊ธฐ์„œ์˜ ๋ฌธ์ œ๋Š” ๋‚ด๊ฐ€ vc๋ฅผ ํ˜„์žฌ์˜ ViewController๋กœ ์„ค์ •ํ•ด์„œ ๊ทธ๋Ÿฐ ๊ฒƒ!

 

ํ•ด๊ฒฐ์„ ํ•˜๊ธฐ์œ„ํ•ด์„œ๋Š” ๋ชจ๋‹ฌ์„ ๋„์–ด์ค„ ์ƒˆ๋กœ์šด UIViewController ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ค˜์•ผ ํ•œ๋‹ค. 

 

 

Cocoa Touch Class ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด์ค€๋‹ค. 

 

 

 

Subclass of : ๋ถ€๋ถ„์„ UIViewController๋ฅผ ์ƒ์†ํ•œ ํด๋ž˜์Šค๋กœ ์„ค์ •ํ•ด์ค€๋‹ค. 

 

 

import UIKit

//ModalController.swift
class ModalController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .yellow
    }
}


//ViewController.swift
class ViewController: UIViewController {
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        let ordeListButton = UIButton()
        ordeListButton.setTitle("Show Alert Button", for: .normal)
        ordeListButton.setTitleColor(.white, for: .normal)
        ordeListButton.backgroundColor = .blue
        ordeListButton.frame = CGRect(x: 100, y: 100, width: 200, height: 50)
        self.view.addSubview(ordeListButton)
        
        ordeListButton.addTarget(self, action: #selector(ShowOderList), for: .touchDown)
        
    }
    
    @objc
    func ShowOderList(){
        //์ „ํ™˜ํ•˜๊ณ  ์‹ถ์€ ํ™”๋ฉด์˜ viewController ์ด๋ฆ„
        let vc = ModalController()

        if let orderSheet = vc.sheetPresentationController {
            orderSheet.detents = [.medium()]
        }
        self.present(vc, animated: true)
    }
}

 

 

 

 

์ฝ”๋“œ ์‹คํ–‰ ๊ฒฐ๊ณผ

 

์ œ๋Œ€๋กœ ๋œจ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ