swiftui

SwiftUI Infinity scroll (up and down)

三世轮回 提交于 2021-02-08 06:34:24
问题 This is a simple example of infinity scroll. How add infinity to Up scroll and insert rows at beginning: rows.insert(contentsOf: Array(repeating: "Item 0", count: 20), at: 0) Like apple do this trick in calendar. struct Screen: View { @State var rows: [String] = Array(repeating: "Item", count: 20) private func getNextPageIfNecessary(encounteredIndex: Int) { guard encounteredIndex == rows.count - 1 else { return } rows.append(contentsOf: Array(repeating: "Item", count: 20)) } var body: some

SwiftUI Animation Slide In and Out

霸气de小男生 提交于 2021-02-08 06:33:07
问题 I have a View that will display over another View. The view animation slides in from the right perfectly, but when I click on the Close button, the view disappears without the desired animation of sliding back to the right before disappearing. I have tried using .opacity(self.isShowing ? 1 : 0), but then the View fades in and out, I need it to slide in and out. Other variations have not produced the desired results. What am I doing wrong? Any guidance, even a duplicate solution (that I could

How to use “*.scnp” file in SwiftUI for button click (iOS)?

风格不统一 提交于 2021-02-08 05:56:06
问题 I have "Explode.scnp" SceneKit file. It's already configured, the texture has been set. How we can use it in SwiftUI? For example, after the button clicks the background will be animated once. var body: some View { ZStack { VStack { Button(action: { Particles() }) { Text("Animate") } } } } This code works for scn. but how to use it with scnp? import SwiftUI import SceneKit struct ScenekitView : UIViewRepresentable { let scene = SCNScene(named: "art.scnassets/ship.scn")! func makeUIView

How to use “*.scnp” file in SwiftUI for button click (iOS)?

最后都变了- 提交于 2021-02-08 05:55:55
问题 I have "Explode.scnp" SceneKit file. It's already configured, the texture has been set. How we can use it in SwiftUI? For example, after the button clicks the background will be animated once. var body: some View { ZStack { VStack { Button(action: { Particles() }) { Text("Animate") } } } } This code works for scn. but how to use it with scnp? import SwiftUI import SceneKit struct ScenekitView : UIViewRepresentable { let scene = SCNScene(named: "art.scnassets/ship.scn")! func makeUIView

SwiftUI Core Data Binding TextFields in DetailView

家住魔仙堡 提交于 2021-02-08 05:55:51
问题 I have a SwiftUI app with SwiftUI App lifecycle that includes a master-detail type list driven from CoreData. I have the standard list in ContentView and NavigationLinks to the DetailView. I pass a Core Data entity object to the Detailview. My struggle is setting-up bindings to TextFields in the DetailView for data entry and for editing. I tried to create an initializer which I could not make work. I have only been able to make it work with the following. Assigning the initial values inside

SwiftUI pause/resume rotation animation

强颜欢笑 提交于 2021-02-08 05:17:42
问题 So far I've seen the following technique for stopping an animation, but what I'm looking for here is that the rotating view stops at the angle it was at the moment and not return to 0. struct DemoView: View { @State private var isRotating: Bool = false var foreverAnimation: Animation { Animation.linear(duration: 1.8) .repeatForever(autoreverses: false) } var body: some View { Button(action: { self.isRotating.toggle() }, label: { Text("🐰").font(.largeTitle) .rotationEffect(Angle(degrees:

SwiftUI: action while pressing a button

半腔热情 提交于 2021-02-08 05:14:55
问题 I’m trying to implement a long press button that changes the SF Symbol that I’m using only when I’m pressing down on the button. I’m not really sure where I should use the the Images as well. The problem is that when the I stop pressing, the button is triggered. Is there a way to don’t activate it (except while pressing down)? What I’m looking for is a button that: When pressed for 2 seconds, the Symbol changes , and after those 2 seconds, when released , the Symbol go back to the initial

Swiftui getting an image's displaying dimensions

回眸只為那壹抹淺笑 提交于 2021-02-08 05:12:11
问题 I'm trying to get the dimensions of a displayed image to draw bounding boxes over the text I have recognized using apple's Vision framework. So I run the VNRecognizeTextRequest uppon the press of a button with this funcion func readImage(image:NSImage, completionHandler:@escaping(([VNRecognizedText]?,Error?)->()), comp:@escaping((Double?,Error?)->())) { var recognizedTexts = [VNRecognizedText]() var rr = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) let requestHandler

Swiftui getting an image's displaying dimensions

荒凉一梦 提交于 2021-02-08 05:12:10
问题 I'm trying to get the dimensions of a displayed image to draw bounding boxes over the text I have recognized using apple's Vision framework. So I run the VNRecognizeTextRequest uppon the press of a button with this funcion func readImage(image:NSImage, completionHandler:@escaping(([VNRecognizedText]?,Error?)->()), comp:@escaping((Double?,Error?)->())) { var recognizedTexts = [VNRecognizedText]() var rr = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height) let requestHandler

Remove/Change list highlight-color (or adjust space between items)

佐手、 提交于 2021-02-08 03:26:11
问题 I am currently making a custom row template for a SwiftUI-list for a MacOS -application. Since i didn't find a way remove/adjust the blue highlight-color (I only found solutions for iOS), I made the the following template which covers the blue-part but "mimics" it within the desired area, which looks like this: Screenshot. I managed to cover most of the highlight-color by using negative paddings, etc.; however, I just can't get rid of some blue pixels on the top of the item (marked in