Swift Device Orientation обновляется неправильноIOS

Программируем под IOS
Ответить
Anonymous
 Swift Device Orientation обновляется неправильно

Сообщение Anonymous »


I want to detect device orientation in swift so that I can apply the correct orientation to a video. The code I have for updating device orientation works correctly but is extremely sensitive to tiny movements. Holding the device upward and barely tilting it causes the device orientation to update to a landscape orientation even though the phone is basically still portrait. Is there a way to lower the sensitivity for device orientation so that tiny movements dont cause an unwanted update?
struct TopVideo: View { var body: some View { ZStack { } .onRotate { newOrientation in withAnimation(.easeInOut(duration: 0.2)){ orien = newOrientation } } } } struct DeviceRotationViewModifier: ViewModifier { let action: (UIDeviceOrientation) -> Void func body(content: Content) -> some View { content .onAppear() .onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in action(UIDevice.current.orientation) } } } extension View { func onRotate(perform action: @escaping (UIDeviceOrientation) -> Void) -> some View { self.modifier(DeviceRotationViewModifier(action: action)) } }

Источник: https://stackoverflow.com/questions/780 ... ncorrectly
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»