์๋ ํ์ธ์~
์ค๋์ UITableView์ ์ ์ค์ฒ๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ์ ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค.
ํ์ฌ Tabman์ด๋ผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ฉด์ UITableView๊ฐ ์๋ View์์๋
UITableView ์์ฒด์ ์ธ๋ก ์คํฌ๋กค ์ ์ค์ฒ ๋๋ฌธ์
ํญ ๊ฐ์ ์ ํ์ด ๋์ง ์๋ ์ด์๊ฐ ์์์ต๋๋ค.
์์ธ
iOS์์ ๊ธฐ๋ณธ์ ์ผ๋ก ๋ชจ๋ View๋ ํ๋์ ์ ์ค์ฒ๋ง์ ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์
UITableView์์๋ ๊ฐ๋ก๋ฐฉํฅ์ ์ ์ค์ฒ๋ฅผ ์ฌ์ฉํ ์ ์์์ต๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก UITableView์๋ ์ธ๋ก๋ก ์คํฌ๋กค์ ํ๊ธฐ ์ํด ์ ์ค์ฒ๊ฐ ๋ค์ด๊ฐ ์๊ธฐ ๋๋ฌธ์ด์ฃ .
ํด๊ฒฐ๋ฐฉ๋ฒ
์ผ๋จ ์ฝ๋๋ถํฐ ๋ณด๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeGesture(_:)))
swipeGesture.direction = UISwipeGestureRecognizer.Direction.right
swipeGesture.delegate = self
tableView.addGestureRecognizer(swipeGesture)
extension MyViewController: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
}
1. ๊ฐ์ฅ ๋จผ์ UITableView์ ์ถ๊ฐํ UISwipeGestureRecognizer๋ฅผ ์ ์ธํ๊ณ ์ค์์ดํ ๋ฐฉํฅ์ ์ค์ ํฉ๋๋ค.
2. ๋ค์ delegate ๋๋ฆฌ์๋ฅผ ์ค์ ํ๊ณ ํ ์ด๋ธ๋ทฐ์ ํด๋น ์ ์ค์ฒ๋ฅผ ์ถ๊ฐํฉ๋๋ค.
UIGestureRecognizerDelegate์ ๋ฉ์๋๋ฅผ ํ์ธํด ๋ณด๋ฉด
shouldRecognizeSimultaneouslyWith otherGestureRecognizer๊ฐ ๋ณด์ด์ค ๊ฒ๋๋ค.
์ฆ, ํ์ฌ MyViewController์์ ๋ค๋ฅธ ์ ์ค์ฒ์ ํจ๊ป ๋์์ ์ฌ์ฉํ ์ ์๋ ๋ค๋ฅธ ์ ์ค์ฒ๋ฅผ ์ธ์ํ ์ ์๊ฒ ํด ์ฃผ๊ฑฐ๋ ํน์ ๋ถ๊ฐ๋ฅํ๊ฒ ๋ง๋ค์ด์ฃผ๋ ๋ฉ์๋์ ๋๋ค.
๊ฒฐ๊ณผ์ ์ผ๋ก true๋ก ์ค์ ํด ์ฃผ๊ฒ ๋๋ฉด UItableView์์๋ ๊ฐ๋ก๋ฐฉํฅ์ ์คํฌ๋กค๋ ์ธ์ํ ์ ์๊ฒ ๋ฉ๋๋ค.
๋ฐ๋ผ์ handleSwipeGesture ๋ฉ์๋๊ฐ ๋์ํ๋ฉด์ ํญ ๊ฐ ์ ํ์ด ๋์ง ์๋ ์ด์๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค.
์ค๋์ ์ฌ๊ธฐ๊น์ง ์ ๋ฆฌํด ๋ณด๊ฒ ์ต๋๋ค : )
๋์์ด ๋์ จ์ผ๋ฉด ์ข๊ฒ ๋ค์.
๊ทธ๋ผ ์ด๋ง ๐ช๐ป๐ช๐ป
'iOS > Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Swift] ๋ฉ๋ชจ๋ฆฌ ๋์๋ฅผ ํด๊ฒฐํด๋ณด์(feat.map) (0) | 2024.02.20 |
---|---|
[Swift] ์๋ชป๋ Coordinator ์ฌ์ฉ ๊ทธ๋ฆฌ๊ณ ๋ฆฌํฉํ ๋ง (0) | 2024.01.16 |
[Swift] Extension์ ๋ํด์ ์์๋ณด์. (1) | 2023.04.13 |
[Swift] Property(ํ๋กํผํฐ)์ ๋ํด์ ์์๋ณด์. (0) | 2023.04.08 |
[Swift] Class์ Struct์ ๋ํด์ (0) | 2023.04.07 |