iOS/Swift

[swift] ๋ฒ„ํŠผํด๋ฆญ ์‹œ ๋“œ๋กญ๋‹ค์šด๋˜๋Š” ๋ทฐ๋ฅผ ๋งŒ๋“ค๊ธฐ

๊ฒฝํ‘ธ 2022. 3. 2. 19:45
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š”~

 

์˜ค๋Š˜์€ ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉํ–ˆ๋˜ ๋“œ๋กญ๋‹ค์šด ๋ทฐ์— ๋Œ€ํ•ด์„œ ์ •๋ฆฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค : )

 

๊ตฌํ˜„ํ–ˆ๋˜ ๋“œ๋กญ๋‹ค์šด ๋ทฐ๋Š” ๋‹ค์Œ์˜์ƒ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

์‹คํ–‰ํ™”๋ฉด
ezgif com-gif-maker

์˜์ƒ ์„ค๋ช…

๋‹ค๋ฅธ ์œ ์ €์™€์˜ ์ฑ„ํŒ…ํ™”๋ฉด์—์„œ ๋ฉ”๋‰ด๋ฒ„ํŠผ์„ ํด๋ฆญํ•  ์‹œ

์œ ์ € ์‹ ๊ณ , ์•ฝ์† ์ทจ์†Œ, ๋ฆฌ๋ทฐ ๋“ฑ๋ก ์„ธ ๊ฐ€์ง€ ๋ฒ„ํŠผ์ด ๋‚ด๋ ค์˜ต๋‹ˆ๋‹ค.

 

๋“œ๋กญ๋‹ค์šด ๊ตฌํ˜„ํ•˜๊ธฐ

์ฒซ ๋ฒˆ์งธ , ๋“œ๋กญ ๋‹ค์šด ํ•  ๋ทฐ๋ฅผ ๋งŒ๋“ค๊ธฐ

๊ฐ€์žฅ ๋จผ์ € ๋“œ๋กญ๋‹ค์šดํ•  ๋ทฐ๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. 

๊ฐ๊ฐ์˜ ๋ฒ„ํŠผ์€ x ์ขŒํ‘œ๋ฅผ ๋น„์œจ์— ๋”ฐ๋ผ ์„ค์ •ํ•ด์ฃผ์—ˆ๋Š”๋ฐ

๊ฐ€์šด๋ฐ ์žˆ๋Š” ๊ฒƒ์„ ์ค‘์•™์— ๋‘๊ณ  ์–‘์ชฝ์œผ๋กœ ๋น„์œจ์— ๋งž๊ฒŒ ๋ฐฐ์น˜ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

final class DropDownView: UIView {
    // ์‹ ๊ณ  ๋ฒ„ํŠผ    
    let reportButton = UIButton().then {
        $0.configuration = .menuStyle(title: "์ƒˆ์‹น ์‹ ๊ณ ", image: R.image.siren()!)
        $0.layer.borderWidth = 0
        $0.layer.borderColor = UIColor.clear.cgColor
    }
    // ์•ฝ์† ์ทจ์†Œ ๋ฒ„ํŠผ
    let cancelButton = UIButton().then {
        $0.configuration = .menuStyle(title: "์•ฝ์† ์ทจ์†Œ", image: R.image.cancelMatch()!)
        $0.layer.borderWidth = 0
        $0.layer.borderColor = UIColor.clear.cgColor
    }
    // ๋ฆฌ๋ทฐ๋“ฑ๋ก ๋ฒ„ํŠผ
    let reviewButton = UIButton().then {
        $0.configuration = .menuStyle(title: "๋ฆฌ๋ทฐ ๋“ฑ๋ก", image: R.image.write()!)
        $0.layer.borderWidth = 0
        $0.layer.borderColor = UIColor.clear.cgColor
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = R.color.basicWhite()!
        setUI()
        setConstraints()
    }
    
    private func setUI() {
        addSubview(reportButton)
        addSubview(cancelButton)
        addSubview(reviewButton)
    }
    
    func setConstraints() {
        reportButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview().multipliedBy(0.4)
            make.centerY.equalToSuperview()
            make.width.equalTo(90)
            make.height.equalTo(75)
        }
        
        cancelButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
            make.width.equalTo(90)
            make.height.equalTo(75)
        }
        
        reviewButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview().multipliedBy(1.6)
            make.centerY.equalToSuperview()
            make.width.equalTo(90)
            make.height.equalTo(75)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

 

๋‘ ๋ฒˆ์งธ , ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ์— ๊ฐ์ฒด ์ƒ์„ฑ ๋ฐ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ตฌํ˜„

1. setMenu ํ•จ์ˆ˜

- ๋‚ด๋น„๊ฒŒ์ด์…˜ ๋ฐ”์˜ ๋†’์ด๋ฅผ ๊ธฐ์ค€์œผ๋กœ y ํฌ์ง€์…˜์„ ์žก์•„์ฃผ๊ณ  ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ์ข…๋ฃŒ๋˜๋Š” ์‹œ์ ์— touchView๋ฅผ ์ด์šฉํ•ด alpha๊ฐ’์„ ์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋•Œ touchVIew๋Š” ๋“œ๋กญ๋‹ค์šด๋˜๋Š” ๋ทฐ๋ฅผ ์ œ์™ธํ•œ ์˜์—ญ์—๋งŒ alpha๊ฐ’์„ ์ฃผ์–ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€์ ์œผ๋กœ ๋„ฃ์€ ์ปค์Šคํ…€ ๋ทฐ์ž…๋‹ˆ๋‹ค.

 

2. resetMenu ํ•จ์ˆ˜ 

- ๊ธฐ์กด์˜ setMenu ํ•จ์ˆ˜์˜ ์ˆ˜ํ–‰์„ ์ •๋ฐ˜๋Œ€๋กœ ์ ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค. ( touchView์™€ ๋“œ๋กญ๋‹ค์šด๋ทฐ๋ฅผ ๋‚ด๋น„๊ฒŒ์ด์…˜ ๋ฐ”๋งŒํผ ๋†’์ด๋ฅผ ์„ค์ •ํ•˜์—ฌ ํ™”๋ฉด์— ๋ณด์ด์ง€ ์•Š๊ฒŒ ์กฐ์ •)

 

 

3. ์ „์ฒด ์ฝ”๋“œ

final class ChattingViewController: BaseViewController {

    let dropDown = DropDownView()
    
    '''
    ์ƒ๋žต
    '''
    
    override func viewDidLoad(){
    	super.viewDidLoad()
        
        // showMenu
     	self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: R.image.more()!, style: .plain, target: self, action: #selector(setMenu))
        
        '''
        ์ƒ๋žต
        '''
    }
    
    '''
    ์ƒ๋žต
    '''
    
    @objc
    private func setMenu() {
        
        UIView.animate(withDuration: 0.5, delay: 0.01, options: .transitionCurlDown) {
            let height = self.navigationController?.navigationBar.frame.maxY
            self.chatMenu.frame = CGRect(x: 0, y: height!, width: UIScreen.main.bounds.width, height: 100)
        } completion: { _ in
            self.touchView.frame = CGRect(x: 0, y: self.chatMenu.frame.maxY, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
        }
    }
    
    private func resetMenu() {
        
        let height = self.navigationController?.navigationBar.frame.maxY
        
        self.touchView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: height!)
        
        UIView.animate(withDuration: 0.5, delay: 0.01, options: .transitionCurlUp) {
            self.chatMenu.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: height!)
        } completion: { _ in }
    }
}

 

UIView์˜ animate ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ–ˆ๊ณ 

์ด๋•Œ ์˜ต์…˜์„ transitionCurlDown๊ณผ transitionCurlUp์„ ์‚ฌ์šฉํ•ด ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

setMenu ๋ฉ”์„œ๋“œ์—์„œ๋Š”

๋“œ๋กญ๋‹ค์šด ๋  ๋ทฐ์ธ chatMenu์˜ ํ”„๋ ˆ์ž„์„ ๋‚ด๋น„๊ฒŒ์ด์…˜ ๋ฐ” ๋ฐ‘์œผ๋กœ ์กฐ์ •ํ•˜๊ณ 

์• ๋‹ˆ๋ฉ”์ด์…˜์ด ๋๋‚˜๋Š” ์‹œ์ ์— touchView๋ฅผ ๊ทธ ๋ฐ‘์œผ๋กœ ํ”„๋ ˆ์ž„์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

resetMenu๋Š” setMenu์™€ ์ •๋ฐ˜๋Œ€๋กœ ์ง„ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

 

์ฒ˜์Œ์—๋Š” ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ๋ ์ง€ ๊ฐ์ด ์˜ค์ง€ ์•Š์•˜์ง€๋งŒ

๋‹จ์ˆœํ•˜๊ฒŒ ์ƒ๊ฐํ•˜๊ณ  ์ ‘๊ทผํ•˜๋‹ˆ ํฌ๊ฒŒ ์–ด๋ ต์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

๋” ์ข‹์€ ๋“œ๋กญ๋‹ค์šด ๋ทฐ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•„์‹ ๋‹ค๋ฉด ๋Œ“๊ธ€ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿผ ์ด๋งŒ ๐Ÿ‘‹๐Ÿป ๐Ÿ‘‹๐Ÿป ๐Ÿ‘‹๐Ÿป

๋ฐ˜์‘ํ˜•