반응형
SwiftUI에서 아이폰 회전시 Landscape, Portrait 이벤트를 처리하기 위해서 다음과 같이 사용할 수 있습니다.
var body: some View {
VStack {
...
}
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
switch UIDevice.current.orientation {
case .landscapeLeft, .landscapeRight:
print("Landscape orientation")
case .portrait, .portraitUpsideDown:
print("Portrait orientation")
default:
print("Unknown or face-up/down orientation")
}
}
}
반응형
'개발 > SwiftUI' 카테고리의 다른 글
foregroundColor vs tint (0) | 2023.10.28 |
---|---|
SwiftUI Color Hex 값으로 생성하기 (0) | 2023.10.08 |
SwiftUI + UIKit (0) | 2023.05.10 |
Using TimelineView and Canvas in SwiftUI (0) | 2022.01.27 |
Understanding Data Flow in SwiftUI (0) | 2021.01.05 |
How to Create a Neumorphic Design With SwiftUI (1) | 2020.06.01 |
How to fix a Form Picker or a NavigationLink that isn’t tappable (0) | 2019.12.06 |
How to fix images not resizing (0) | 2019.12.06 |