swiftui

Fatal Error: Duplicate keys of type 'Geocoded Placemark' were found in a dictionary. (Mapbox Geocoder)

旧街凉风 提交于 2021-01-28 01:50:48
问题 I quote: "This usually means either that the type violates Hashable's requirements, or that members of such a dictionary were mutated after insertion." I'm using the Mapbox Geocoder , and when this runtime error occured, my XCode brought me to Thread 1, 0_swift_runtime_on_report and the error occured on the commented line below: libswiftCore.dylib`_swift_runtime_on_report: 0x10fdd2180 <+0>: pushq %rbp //this line right here I've never seen this error before and I don't even begin to know how

Getting SwiftUI wrapper of AVPlayer to pause when view disappears

我是研究僧i 提交于 2021-01-28 00:45:09
问题 TL;DR Can't seem to use binding to tell wrapped AVPlayer to stop — why not? The "one weird trick" from Vlad works for me, without state & binding, but why? See Also My question is something like this one but that poster wanted to wrap an AVPlayerViewController and I want to control playback programmatically. This guy also wondered when updateUIView() was called. What happens (Console logs shown below.) With code as shown here, The user taps "Go to Movie" MovieView appears and the vid plays

How can I get SKEmitterNode to work in SwiftUI?

徘徊边缘 提交于 2021-01-28 00:35:43
问题 I'm trying to update the colour of an SKEmitterNode within a UIViewRepresentable . The hue value is passed in from the state on the parent View, and the emitter colour should update when the hue value in the parent state updates. It initially displays, and although it updates on the first call to updateUIView it does not respond to any subsequent calls, even though the function definitely gets called with the new value of hue each time. Has anyone any idea why the emitter won't update? I'm at

How to apply animation for one specific modifier change only?

南笙酒味 提交于 2021-01-27 22:25:43
问题 How to only apply .animation to .offset while keeping other modifier change not affected by it. Adding .animation after offset would also animate the font size changing. // Main view var body: some View { GeometryReader { geo in VStack { DynamicText() } .frame(height: geo.size.height) .offset(y: self.viewModel.offset ? 5.0 : 0) .animation(.default) } } // DynamicText view var body: some View { return GeometryReader { geo in VStack { Text("Foo") .font( .system(size: geo.size.height * 0.95,

How do I make a SwiftUI gesture that keeps running code while the view is pressed

北战南征 提交于 2021-01-27 21:54:22
问题 I am trying to make a button that controls a counter. If you tap it, the counter goes up by one. But if you tap and hold it, I want the counter to go up by one every n seconds while you are holding it and keep doing that until you let go. If I use code like: @GestureState var isDetectingLongPress = false var plusLongPress: some Gesture { LongPressGesture(minimumDuration: 1) .updating($isDetectingLongPress) { currentstate, gestureState, _ in gestureState = currentstate } .onEnded { finished in

SwiftUI - Animate path shape stroke drawing

丶灬走出姿态 提交于 2021-01-27 21:16:30
问题 Is there a way to animate the stroke drawing of a path whenever its destination point changes? Here is a snippet of my code: struct JourneyMapLineView: View { @Binding var rects: [CGRect] var body: some View { rects.count != 0 ? JourneyMapLineShape(startRect: rects[0], endRect: rects[rects.count-1]) .stroke(Color.red), lineWidth: 8) .animation(.easeInOut(duration: 0.3)) //<-- Is not working : nil } } struct JourneyMapLineShape: Shape { var startRect: CGRect var endRect: CGRect func path(in _:

SwiftUI: Picker doesn't update text in same view

十年热恋 提交于 2021-01-27 20:58:07
问题 I have this simple situation: struct User: Hashable, Identifiable { var id: Int var name: String func hash(into hasher: inout Hasher) { hasher.combine(id) } } let bob = User(id: 1, name: "Bob") let john = User(id: 2, name: "John") let users = [bob, john] struct ParentView: View { @State private var user: User? var body: some View { VStack(spacing: 0) { // Other elements in view... Divider() ChildPickerView(user: $user) Spacer() } } } struct ChildPickerView: View { @Binding var user: User? var

How to call a uikit viewcontroller method from swiftui view

我只是一个虾纸丫 提交于 2021-01-27 20:39:10
问题 I have looked all over for the answer to this question and can't seem to find it. How can I call a viewController method from swiftUI (e.g. on a button click)? I have a viewcontroller that looks like this: import Player class PlayerViewController: UIViewController { var player = Player() func play() { self.player.play() } } And I have a wrapper that looks like this: import SwiftUI import AVFoundation struct ProjectEditorPlayerBridge: UIViewControllerRepresentable { func makeUIViewController

Issues implementing navigation from a main controller to page based controllers in WatchOS using SwiftUI

我只是一个虾纸丫 提交于 2021-01-27 20:08:50
问题 I'm trying to do do something like this using SwiftUI. So far I have the ability to go from one main view to a page based views but I cannot scroll between the page views. The storyboard looks like this: As you can see I do not have any segues or next page relationships in the storyboard. I'm implementing those in code in the WKHostingController of HC3 (the middle one of the three). HostingController of HC3 : class HC3: WKHostingController<CV> { override func awake(withContext context: Any?)

How do I pass a View into a struct while getting its height also?

梦想的初衷 提交于 2021-01-27 19:51:08
问题 I'm trying to make a View that will put a Blur() at the bottom of an iPhone layout, respecting safeareas and that I can easily reuse. Something like this: import SwiftUI struct SafeBottomBlurContainer: View { @Environment(\.colorScheme) var colorScheme var body: some View { GeometryReader { geometry in VStack { Spacer() ZStack { Blur(style: self.colorScheme == .dark ? .systemThinMaterialDark : .systemThinMaterialLight) .frame( width: geometry.size.width, height: geometry.safeAreaInsets.bottom