티스토리 뷰
728x90
반응형
탭뷰의 아이템 터치 시 탭 전환 말고 Navigation 이동

/// iOS 16 이상 버전
struct ContentView: View {
@State private var isDetailViewPresented = false
@State private var selectedTabIndex = 0
var body: some View {
NavigationStack {
TabView(selection: $selectedTabIndex) {
Text("Tab 0 Content")
.tabItem {
Image(systemName: "0.circle.fill")
Text("Tab 0")
}
.tag(0)
Text("Tab 1 Content")
.tabItem {
Image(systemName: "1.circle.fill")
Text("Tab 1")
}
.tag(1)
Text("Tab 2 Content")
.tabItem {
Image(systemName: "2.circle.fill")
Text("Tab 2")
}
.tag(2)
}
.onChange(of: selectedTabIndex) { oldValue, newValue in
if newValue == 2 {
self.selectedTabIndex = oldValue
isDetailViewPresented = true
}
}
.navigationDestination(isPresented: $isDetailViewPresented) {
Text("navigationDestination")
}
}
}
}
/// iOS 16 미만 버전
struct ContentView2: View {
@State private var isDetailViewPresented = false
@State private var selectedTabIndex = 0
var body: some View {
NavigationView {
TabView(selection: $selectedTabIndex) {
Text("Tab 0 Content")
.tabItem {
Image(systemName: "0.circle.fill")
Text("Tab 0")
}
.tag(0)
Text("Tab 1 Content")
.tabItem {
Image(systemName: "1.circle.fill")
Text("Tab 1")
}
.tag(1)
Text("Tab 2 Content")
.tabItem {
Image(systemName: "2.circle.fill")
Text("Tab 2")
}
.tag(2)
}
.onChange(of: selectedTabIndex) { [selectedTabIndex] newTab in
if newTab == 2 {
self.selectedTabIndex = selectedTabIndex
isDetailViewPresented = true
}
}
.background(
NavigationLink(
destination: Text("NavigationLink"),
isActive: $isDetailViewPresented
) {
EmptyView()
}
.hidden()
)
}
}
}
iOS
Swift
Xcode
SwiftUI
스유
728x90
반응형
'iOS SwiftUI' 카테고리의 다른 글
| iOS SwiftUI Custom Slider 커스텀 슬라이더 (제어센터 UI) (0) | 2024.08.01 |
|---|---|
| [TIL] iOS SwiftUI 글자수, 단어수, 줄수 세기 + 복사, 공유, 툴바, 키보드 닫기 등 (0) | 2024.07.01 |
| iOS SwiftUI 드래그 앤 드롭 Drag And Drop (DND) (0) | 2024.04.01 |
| iOS SwiftUI PageControl 페이지 컨트롤 (0) | 2024.03.01 |
| iOS SwiftUI FlowLayout 컨텐츠 크기 만큼 아래로 배치 되는 레이아웃 (2) | 2024.02.01 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 테이블뷰
- Infinite Carousel
- 스위프트
- presentationcompactadaptation
- indicator
- swiftUI
- picker
- permission
- TabBar
- Authorization
- 로컬라이징
- Language
- 인디케이터
- localizable
- 리젝
- 아이오에스
- SKPayment
- 엑스코드
- 다국어
- SWIFT
- Reject
- ios
- localizing
- TabView
- 심사
- AppStore
- Xcode
- 프로그레스
- 현지화
- custom segment
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함