티스토리 뷰
ZStack은 Stack안에 있는 자식 뷰들을 z축으로 중첩시켜주는 view 입니다.

실제 쓰이는 경우들을 알게 되어서 정리합니다-!
[1] 카메라와 컨트롤
이런 카메라 앱을 만든다고 할때,
카메라뷰랑 컨트롤 버튼들(파란네모친 영역)를 zstack을 이용하여 동시에 띄울 수 있습니다.

struct ContentView: View { | |
var body: some View { | |
let cameraView = CameraView() | |
return ZStack { | |
cameraView | |
.edgesIgnoringSafeArea(.all) | |
.scaledToFill() | |
ControlView(cameraView: cameraView) | |
} | |
} | |
} |
더불어 컨트롤뷰의 HStack(갤러리 열기, 촬영, 필터 버튼들이 있음)를 bottom에서부터 height 200으로 위치잡아주고 싶다면
Spacer를 활용할수있습니다. (신기)
struct ControlView: View { | |
... | |
var body: some View { | |
... | |
return VStack { | |
Spacer() | |
HStack(alignment: .center, spacing: 30) { | |
Button(action: { | |
self.showImagePicker = true | |
}, label: { | |
Text("open gallery") | |
}).sheet(isPresented: $showImagePicker, content: { | |
imagePicker | |
}) | |
Button(action: { | |
self.cameraView.takePhoto() | |
}, label: { | |
Circle() | |
.frame(width: 100, height: 100) | |
.foregroundColor(.white) | |
}) | |
Button(action: { | |
print("현재 카메라의 필터를 바꾸기") | |
}, label: { | |
Text("필터버튼") | |
}) | |
}.frame(height: 200) | |
} | |
} | |
} |
[2] SwiftUI의 Fullscreen Modal을 띄울때
SwiftUI에서는 현재 fullscreen 모달을 띄울 수 있는 설정이 없습니다..😭
그래서 zstack을 활용해서 fullscreen presentation을 한 것 처럼 보이게 하시더라구요...!!
forums.developer.apple.com/thread/127839
SwiftUI:how to get the secondView showed in ful... |Apple Developer Forums
SwiftUI: I am trying to transfer to secondView from firstView on iPad Pro(11inch) Horizontal screen,the secondView can not be showed in full screen here is my code: import SwiftUI struct ContentView: View { @State var showsecondView: Bool = false
forums.developer.apple.com
www.youtube.com/watch?v=514A7yzznJE
⚠️ 참고 ⚠️
저는 iOS13일때 이 글을 쓴건데,
iOS 14부터 fullScreenCover(isPresented:onDismiss:content:) 를 사용하시면 됩니다!!
'🍏 > SwiftUI + Combine' 카테고리의 다른 글
[SwiftUI] 뷰의 이니셜라이저에서 @State, @Binding, @EnvironmentObject에 접근하기 (1) | 2020.08.31 |
---|---|
[SwiftUI] Multi-platform App 만들기 - 프로젝트 세팅 (3) | 2020.08.06 |
[Combine] Cancellable과 AnyCancellable (6) | 2019.06.28 |
Rx에서 Combine으로 바꿔본 후기와 느낀점 (2) | 2019.06.28 |
RxSwift vs Combine - 스펙 / 성능 / 개념 비교 (16) | 2019.06.28 |
- Total
- Today
- Yesterday
- Watch App for iOS App vs Watch App
- cocoapod
- ribs
- flutter deep link
- Django Heroku Scheduler
- METAL
- Flutter Clipboard
- flutter build mode
- 플러터 싱글톤
- github actions
- ipad multitasking
- Flutter getter setter
- Django Firebase Cloud Messaging
- Flutter Spacer
- Dart Factory
- drf custom error
- PencilKit
- 장고 URL querystring
- DRF APIException
- flutter dynamic link
- Django FCM
- flutter 앱 출시
- Flutter 로딩
- 장고 Custom Management Command
- Sketch 누끼
- 구글 Geocoding API
- 플러터 얼럿
- Flutter Text Gradient
- Python Type Hint
- SerializerMethodField
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |