uiviewrepresentable

SwiftUI - iOS 13 UIViewRepresentable of WKWebView gets Thread 1: EXC_BREAKPOINT crash

佐手、 提交于 2021-02-07 19:27:38
问题 I'm trying to port WKWebView over to SwiftUI. Here's my code: import SwiftUI import WebKit struct ContentView: View { var body: some View { WebViewWrapper() } } /** WKWebView ported over to SwiftUI with `UIViewRepresentable`. */ final class WebViewWrapper: UIViewRepresentable { /// `UIViewRepresentable` required function #1. func makeUIView(context: Context) -> WKWebView { print("make") let webView = WKWebView() /// EXC_BREAKPOINT error here return webView } /// `UIViewRepresentable` required

Tapping an MKMapView in SwiftUI

耗尽温柔 提交于 2021-01-29 19:43:14
问题 I have a map in a SwiftUI app. It is working up to a point; but now I want to be able to tap on it and know the latitude and longitude of the tap. Here is the current code: import SwiftUI import MapKit struct MapView: UIViewRepresentable { @Binding var centerCoordinate: CLLocationCoordinate2D func makeUIView(context: Context) -> MKMapView { let mapView = MKMapView() mapView.delegate = context.coordinator let gRecognizer = UITapGestureRecognizer(target: context.coordinator, action: #selector

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

SwiftUI Custom TextField with UIViewRepresentable Issue with ObservableObject and pushed View

混江龙づ霸主 提交于 2021-01-05 08:42:52
问题 I created a UIViewRepresentable to wrap UITextField for SwiftUI, so I can e.g. change the first responder when the enter key was tapped by the user. This is my UIViewRepresentable (I removed the first responder code to keep it simple) struct CustomUIKitTextField: UIViewRepresentable { @Binding var text: String var placeholder: String func makeUIView(context: UIViewRepresentableContext<CustomUIKitTextField>) -> UITextField { let textField = UITextField(frame: .zero) textField.delegate =

Implementing Apple Pay with SwiftUI

折月煮酒 提交于 2020-07-21 03:02:07
问题 This is my first time working with PassKit and with SwiftUI on a big project. I'm trying to implement Apple Pay SwiftUI and since there isn't a native way to do so yet, I tried wrapped the PKPaymentAuthorizationViewController in UIViewControllerRepresentable, but I'm not sure if I'm doing it properly. The view displays properly and seems to work when clicking on it to pay. I control showing the window by binding the view to an isPresentingApplePay bool (see below). The issues happen when the