swiftui

SwiftUI Button on top of a MKMapView does not get triggered

雨燕双飞 提交于 2021-01-05 11:32:43
问题 I have a button on top of a MKMapView. But the button does not get triggered when it's tapped on. Do you know what's missing? MapView.swift import SwiftUI import UIKit import MapKit struct MapView: UIViewRepresentable { func makeUIView(context: Context) -> MKMapView { let mkMapView = MKMapView() return mkMapView } func updateUIView(_ uiView: MKMapView, context: Context) { } func makeCoordinator() -> Coordinator { Coordinator() } class Coordinator: NSObject, MKMapViewDelegate { } } ContentView

Using ARKit anchor to place RealityKit Scene

為{幸葍}努か 提交于 2021-01-05 11:23:32
问题 I am currently struggling to add an RealityKit Scene to an ARKit anchor. As my previous question, it is not possible to directly add the RealityKit Scene to an ARKit Anchor Node. But how can I use the ARKit Anchor to place my Scene? For example, I want to find an object in the room, and depending on which object I found, I want to use different scenes and anchor them in the room depending on the recognised objects position. Thanks for the help. Current try: func makeUIView(context: Context) -

How to fix multiple SwiftUI previews for text

谁都会走 提交于 2021-01-05 11:05:37
问题 I am working with SwiftUI and wrote the following example to present an issue I'm experiencing. When I add multiple Buttons, or multiple Texts, it creates two separate previews, but when I run the application on a device they load simultaneously. Attached here is a photo: I cleaned my build folder, restarted my computer, and tried this on various other SwiftUI files but no success. Any ideas? 回答1: You'll need to put both Text s in a VStack or similar. struct ContentView: View { var body: some

How to fix multiple SwiftUI previews for text

强颜欢笑 提交于 2021-01-05 11:05:03
问题 I am working with SwiftUI and wrote the following example to present an issue I'm experiencing. When I add multiple Buttons, or multiple Texts, it creates two separate previews, but when I run the application on a device they load simultaneously. Attached here is a photo: I cleaned my build folder, restarted my computer, and tried this on various other SwiftUI files but no success. Any ideas? 回答1: You'll need to put both Text s in a VStack or similar. struct ContentView: View { var body: some

Changing the colour of specific list elements SwiftUI

自作多情 提交于 2021-01-05 09:12:23
问题 I have a list of 'players' in my app, and I want to some of them to have a different background colour depending on their properties. Every Player object has a .active property that is either true or false. Depending on this value I want the background of that row to be a light grey rather than the white of the others. How would I do this? I was hoping it would be as simple as: List(homeTeam.players) {player in HStack{ Text("\(player.shirtNumber) - \(player.playerName)") Spacer() Text("\

Changing the colour of specific list elements SwiftUI

守給你的承諾、 提交于 2021-01-05 09:12:06
问题 I have a list of 'players' in my app, and I want to some of them to have a different background colour depending on their properties. Every Player object has a .active property that is either true or false. Depending on this value I want the background of that row to be a light grey rather than the white of the others. How would I do this? I was hoping it would be as simple as: List(homeTeam.players) {player in HStack{ Text("\(player.shirtNumber) - \(player.playerName)") Spacer() Text("\

Changing the colour of specific list elements SwiftUI

梦想的初衷 提交于 2021-01-05 09:11:42
问题 I have a list of 'players' in my app, and I want to some of them to have a different background colour depending on their properties. Every Player object has a .active property that is either true or false. Depending on this value I want the background of that row to be a light grey rather than the white of the others. How would I do this? I was hoping it would be as simple as: List(homeTeam.players) {player in HStack{ Text("\(player.shirtNumber) - \(player.playerName)") Spacer() Text("\

Changing the colour of specific list elements SwiftUI

為{幸葍}努か 提交于 2021-01-05 09:11:38
问题 I have a list of 'players' in my app, and I want to some of them to have a different background colour depending on their properties. Every Player object has a .active property that is either true or false. Depending on this value I want the background of that row to be a light grey rather than the white of the others. How would I do this? I was hoping it would be as simple as: List(homeTeam.players) {player in HStack{ Text("\(player.shirtNumber) - \(player.playerName)") Spacer() Text("\

Is there a way to add a third toggle option to an on/off state by .onLongPressGesture?

爷,独闯天下 提交于 2021-01-05 08:53:53
问题 I already have a toggle set up as in the image below to toggle the image on/off or pass / fail. I am trying to add a third state using a long press gesture to the image which will turn the image grey with a slash icon. I have achieved this in the text element as at is doesn't have an bool condition, but after much searching can't figure out how to achieve this with the image. What I am aiming for is something along the lines of: Image(systemName: isPressed ? "checkmark.circle.fill" : "x

swiftUI bottomBar toolbar disappears when going back

泄露秘密 提交于 2021-01-05 08:53:53
问题 I have these swiftUI views and trying to use the toolbar (bottomBar). When you launch the app it appears fine, but after going to View2 using he navigationLink and then go back to the main view the toolbar disappears. It happens when the NavigationLink being inside the list. If you don't use a list (put the navigation link inside a VStack or similar) it works as expected and the toolbar reappears when you go back to the initial view. Is there a way to fix this? import SwiftUI struct View2: