반응형
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")
}
}
}반응형
'Dev Study > SwiftUI' 카테고리의 다른 글
| SwiftUI에서 많이 하는 실수 - @State와 @Binding을 혼동해서 잘못 사용하는 실수 (0) | 2025.12.05 |
|---|---|
| SwiftUI 전용 개발을 위한 최적의 iOS Deploy Target 가이드(25년 기준) (0) | 2025.11.10 |
| SwiftUI + UIKit 혼합 아키텍처 실전 가이드 (0) | 2025.11.10 |
| 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 |

