swiftui

NSViewControllerRepresentable not responding to events when embedded into SwiftUI List

吃可爱长大的小学妹 提交于 2021-01-29 18:24:54
问题 I have the following code snippets: The list element: struct PaletteListRowUIView: View { @State var colorPalette: ColorPalette var isSelected: Bool var onSelect: () -> Void var body: some View { return VStack(alignment: .leading) { HStack { Group { if(isSelected) { Ellipse().fill(Color.white) } else { Ellipse().stroke(Color.white) } }.contentShape(Ellipse()) .aspectRatio(1, contentMode: .fit).frame(width: 10, height: 10) .gesture(TapGesture().onEnded(onSelect)) RenameableText(text:

swiftui, animation applied to parent effect child animation(Part II)

家住魔仙堡 提交于 2021-01-29 17:25:45
问题 PREVIOUS Q: swiftui, animation applied to parent effect child animation Now the TextView has its own state. RectangleView with TextView slide into screen in 3 seconds, but state of TextView changed after a second while sliding. Now you can see TextView stops sliding, go to the destination at once. I Just want RectangleView with TextView as a whole when sliding, and TextView rotates or keeps still as I want. import SwiftUI struct RotationEnvironmentKey: EnvironmentKey { static let defaultValue

SwiftUI hiding a navigation bar only when looking at ContentView

蓝咒 提交于 2021-01-29 16:44:02
问题 I have a Content file and am hiding the navigation bar because it takes up space and pushes elements down. One of the buttons in the ContentView redirects (using a navigation link) to another view. In this other view, the navigationBar is still hidden....for simplicity sake, I'll cut out some of the code from ContentView: //this is the view that looks "fine" (i.e. the navigation bar takes up no space) struct ContentView: View { @State private var isPresentedSettings = false var body: some

Programatic navigation for NavigationView using tag/selection or isActive

冷暖自知 提交于 2021-01-29 16:01:56
问题 NavigationLink has an initializer NavigationLink(destination:, tag:, selection:, label:) that is supposed to be a hidden NavigationLink that gets active when selection == tag. Similiar to NavigationLink(destination:isActive:label:) . Now I wondered, could I use this to have a property in a model that can be used to jump between pages arbitrarily? Aka, to support programatic navigation for NavigationView? Something like this: import SwiftUI enum NavStep { case step1 case step2 } class NavModel

compare angle and up in strange behavior

依然范特西╮ 提交于 2021-01-29 15:02:06
问题 i have a func to compare angles.. if the angles si between the range -5/+5deg from the starting heading this should return Color .green otherwise should return .orange. i simplify the project so it can be easy to use in swift Playground. here my fun: func convertToPositiveAngle(_ angle : Angle) -> Angle { var toRet = Angle(degrees: fmod(angle.degrees, 360)) if toRet.degrees < 0 { toRet.degrees += 360.0; } return toRet } let headingStart = 3.0 let currentHeading = 3.0 func centro(startHeading

SwiftUI view injection into other view

北慕城南 提交于 2021-01-29 14:42:06
问题 I want to create such view hierarchy ZStack { TabView { NavigationView { NavigationLink ... { Subview() } } } FullScreenView() } inside subview there is button which toogles environment variable to present full screen view like in this example: https://github.com/nikishovde/HideTabBarInSubview how to inject subview contents to full screen view when showFullscreen variable is toggled true ? ( I want to make FullScreenView generic so I can use it for different views which I want to present on

How can I add a MapView to another View in Swift?

99封情书 提交于 2021-01-29 14:01:29
问题 I have 2 tabs in my application. On the first one, I display a View (which is myView, a self defined struct) and on the second one I want to display a MapView. I found several tutorials, showing how to add a MapView via Storyboard, but I don't get how I can finally display it in one of my Tabs. The tabs are created as follows: struct ContentView: View { @State private var selection = 0 var body: some View { TabView(selection: $selection){ myView() .font(.title) .tabItem { VStack { Image

Core Data + CloudKit not refreshing on other device automatically?

陌路散爱 提交于 2021-01-29 13:38:56
问题 I have my SwiftUI app working with Core Data + CloudKit. I am able to save new entries to the database from my Mac or iPhone. The app uses the exact same project/codebase for all devices. The only problem is that I need to close out of the app and re-open it to see any new entries made from the other device. I can immediately see the new entries made from the same device, but they do not appear on the other devices until I close and re-open the app on it. Am I missing something here? Do I

SwiftUI Picker with Cloud Firestore

跟風遠走 提交于 2021-01-29 13:36:55
问题 I was wondering whether I was able to get some help on this one, I've been trying a while to get things working and functioning properly and have been able to pass the Firestore data into the picker view, but I'm unable to select the data to view in the 'selected' area. I have added my code and my Firestore setup. Thanks in advance. import SwiftUI import Firebase struct SchoolDetailsView: View { @ObservedObject var schoolData = getSchoolData() @State var selectedSchool: String! var body: some

How to pass full data into another View

*爱你&永不变心* 提交于 2021-01-29 13:25:43
问题 So from using this line: .onReceive(model2.$postsById) { postById in print("Model2 \(postById)") } I get back this data: Model2 [Test.PostById(id: "9ffb2c83-45ed-4198-b6ab-9a259ef91b44", album_id: "9ffb2c83-45ed-4198-b6ab-9a259ef91b44", name: nil, path: "public/1584106997200-astronomy-space-abstract-galaxy.jpg"), Test.PostById(id: "7ac7ff5f-4b4b-458f-b9a6-491813dbe97d", album_id: "9ffb2c83-45ed-4198-b6ab-9a259ef91b44", name: Optional("California Wind "), path: "public/1584106997230-California