LoginSignup
1
1

More than 1 year has passed since last update.

SwiftUIでdeviceのorientationを取得する

Posted at

SwiftUIでdeviceのorientationを取得する方法

.onReceive(NotificationCenter.default.publisher(for:UIDevice.orientationDidChangeNotification)) { _ in
         guard let scene = UIApplication.shared.windows.last?.windowScene else { return }
         self.orientation = scene.interfaceOrientation
   }

UIDevice.current.orientationで取得するUIDeviceOrientationfaceUp
, faceDownのz軸含めた6方向で、今回は4方向の取得をしたかったので、UIInterfaceOrientationを取得している。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1