์๋ ํ์ธ์~
์ค๋์ ํ๋ก์ ํธ์์ ์ฌ์ฉํ๋ ๋๋กญ๋ค์ด ๋ทฐ์ ๋ํด์ ์ ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค : )
๊ตฌํํ๋ ๋๋กญ๋ค์ด ๋ทฐ๋ ๋ค์์์๊ณผ ๊ฐ์ต๋๋ค.
์คํํ๋ฉด |
---|
์์ ์ค๋ช
๋ค๋ฅธ ์ ์ ์์ ์ฑํ ํ๋ฉด์์ ๋ฉ๋ด๋ฒํผ์ ํด๋ฆญํ ์
์ ์ ์ ๊ณ , ์ฝ์ ์ทจ์, ๋ฆฌ๋ทฐ ๋ฑ๋ก ์ธ ๊ฐ์ง ๋ฒํผ์ด ๋ด๋ ค์ต๋๋ค.
๋๋กญ๋ค์ด ๊ตฌํํ๊ธฐ
์ฒซ ๋ฒ์งธ , ๋๋กญ ๋ค์ด ํ ๋ทฐ๋ฅผ ๋ง๋ค๊ธฐ
๊ฐ์ฅ ๋จผ์ ๋๋กญ๋ค์ดํ ๋ทฐ๋ฅผ ๋ง๋ค์์ต๋๋ค.
๊ฐ๊ฐ์ ๋ฒํผ์ 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์ ์ ๋ฐ๋๋ก ์งํํ์ต๋๋ค.
์ฒ์์๋ ์ด๋ป๊ฒ ํด์ผ ๋ ์ง ๊ฐ์ด ์ค์ง ์์์ง๋ง
๋จ์ํ๊ฒ ์๊ฐํ๊ณ ์ ๊ทผํ๋ ํฌ๊ฒ ์ด๋ ต์ง ์์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ ์ข์ ๋๋กญ๋ค์ด ๋ทฐ๋ฅผ ๊ตฌ์ฑํ๋ ๋ฐฉ๋ฒ์ ์์ ๋ค๋ฉด ๋๊ธ ๋ถํ๋๋ฆฝ๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
๊ทธ๋ผ ์ด๋ง ๐๐ป ๐๐ป ๐๐ป
'iOS > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[swift] ์ฑํ UI ๊ตฌํํด๋ณด๊ธฐ(2) (0) | 2022.03.09 |
---|---|
[swift] ์ฑํ UI ๊ตฌํํด๋ณด๊ธฐ(1) (0) | 2022.03.03 |
[swift] UILabel intrinsicContentSize ํ์ฉ๋ฐฉ๋ฒ (0) | 2022.02.23 |
[swift] NavigationController์ setViewController ์ฌ์ฉ๋ฐฉ๋ฒ (0) | 2022.02.18 |
[swift] TableViewCell/CollectionViewCell ์ ์์ ๋ฒํผ์ ์ด๋ฒคํธ๋ฅผ ์ฃผ๋ ๋ฐฉ๋ฒ (0) | 2022.02.17 |