I have a horizontal scroll view and a fixed array. I would like to loop it such that when I scroll left and get near the end, the array will add the items in the beginning to the end so that the user can continue to scroll. I would like this to happen when scrolling both left and right and to not have the current position of the user jump around. Here is my code. What am I missing? Would appreciate any and all help.
import SwiftUI
import Algorithms
struct ContentView: View {
@State private var timePosition = ScrollPosition(idType: Int.self, edge: .leading)
@State private var times: [Int] = Array(0...23)
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 0) {
ForEach(times, id:\.self) { time in
Text("\(time)")
.font(.system(.callout, design: .monospaced, weight: .semibold))
.padding(8)
.frame(width: 180, height: 110, alignment: .topLeading)
.border(width: 1, edges: [.leading, .trailing], color: .primary.opacity(0.05))
.id(time)
}
}
.scrollTargetLayout()
}
.frame(height: 110)
.scrollPosition($timeScrollPosition, anchor: .center)
.onScrollTargetVisibilityChange(idType: Int.self) { timeIDs in
if let currentViewID = model.timeScrollPosition.viewID {
if timeIDs.contains(times[times.count - 2]) {
times.rotate(toStartAt: times.count - 1)
}
if timeIDs.contains(times[1]) {
times.rotate(toStartAt: times.count-1)
}
print("New times: \(times)")
timeScrollPosition.scrollTo(id: currentViewID)
}
}
}
}
Post
Replies
Boosts
Views
Activity
Hi!
Wondering if there's a way to add subject lifting to images in my SwiftUI app without relying on UIViewControllerRepresentable and Coordinators to adopt the ImageAnalysisInteraction protocol.
Thank you!
Hello!
I want to build an app that lets devices with the LiDAR Scanner scan their environment and share their scans with one another. As of now, I can create the mesh using the LiDAR Scanner and export it as an OBJ file.
However, I would like the ability to map textures and colors onto this model. How would one go on to get the real world texture and place it onto the OBJ model?
Thank you!
Hello!
I was wondering if it would be possible for the sample code for the Meal App to be posted. There are some things I'd like to see regarding MLLinearRegressor and how models can be personalized with context and data.
Hello!
I really want to make these immersive AR experiences with engaging graphics like the new AR Spaces feature in the Clips app. Is RealityKit the way to go for this? Or does it require some really lower level understanding and use of API’s like ARKit with Metal?
Also, with RealityKit’s scene understanding, we can map a mesh of the scene the LIDAR device can see but I was wondering how would I switch that out with a custom mesh design like in the Clips app as well.
Thank you!
Hello!
I was wondering if it would be possible for the developers to post the sample code for the Face Mesh demo that used PencilKit to draw a filter on a user's face.
Hello!
I've been trying to replicate the linear regressor tabular application as shown at the end of the WWDC 2021 session Build dynamic iOS apps with the Create ML framework. However, I keep getting the error
Cannot find 'DataFrame' in scope and Cannot find 'Column' in scope.
I was wondering if this is a bug with the current beta or if I have my code wrong. I am trying to run my application on an iPhone 12 Pro running iOS 15 Beta 1. I am using Xcode 13 on Monterey. Thank you!
I have a Reality Composer project that has two scenes. In the first scene, I post a notification from Xcode to trigger an animation and then change the scene to the next scene. This is done using the Change Scene in the Action Sequence.
In the second scene, when the user taps on an object, it should send a notification to Xcode using the Notify action. How do I set the .onAction in Xcode for the second scene if I switch to the second scene using an Action Sequence from the first scene? Thanks!
Hi!
I am attempting to create a style transfer model for images. My content image folder has about 80,000 images. However, when I click train, the Create ML app displayed the “Processing” message for about a minute before I get the error: Could not create buffer with format ‘BGRA’ (-6662). Hope someone can help me with what this issue is! Is my training data too large or are their pictures in there that don’t conform to the right image format? Thank you!
The sample code provided only allows a connection of up to one other device. I was wondering how would one create multiple sessions in Swift, how to handle different devices and their inputs, and how many sessions is the U1 chip capable of handling. Thank you!
I have a custom Core ML model built with Keras that has a couple of updatable layers. I was wondering if I switched this model to be deployed from the cloud rather than packaged with the app, would the on-device personalized changes transfer whenever I deploy a model over the cloud or would a user have to start with a fresh, new model every time?
Similarly, do on-device personalized models work with model encryption? Thanks!
When I tap on a widget, it goes directly to my app. However, I am wondering how do I deep link to various screens in my app from a widget. Is there some sort of NSUserActivity I can read?