Hi! Did you solve it?
Question number 1: I have unfortunately no idea how to do that, I think you need to play around with PencilKit from UIKit and then implementing custom drag gestures for Swift to determine that you want to scroll or paint. However, this should be possible because Apple's own Freeform app can do such.
Question number 2: Did you mean something like this? (before you draw this will have drawn some line on the screen, because you pass lines as a parameter to the draw view)
ContentView(lines: [
Line(points: [
CGPoint(x: 12, y: 426),
CGPoint(x: 12, y: 65)
], color: .black),
Line(points: [
CGPoint(x: 122, y: 412),
CGPoint(x: 425, y: 212)
], color: .black),
Line(points: [
CGPoint(x: 553, y: 2),
CGPoint(x: 1, y: 23)
], color: .black)
], selectedColor: .black)
Post
Replies
Boosts
Views
Activity
Hi! I tried your code!
For me, no line was drawn with the ScrollView, so I tried replacing the ScrollView([.horizontal, .vertical]) with a VStack and then you could draw!
The code that worked:
struct Line {
var points: [CGPoint]
var color: Color
}
struct ContentView: View {
@State var lines: [Line] = []
@State var selectedColor: Color = Color.black
var body: some View {
VStack {
Canvas { ctx, size in
for line in lines {
var path = Path()
path.addLines(line.points)
ctx.stroke(path, with: .color(line.color), style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round))
}
}.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local)
.onChanged({ value in
let position = value.location
if value.translation == .zero {
lines.append(Line(points: [position], color: selectedColor))
} else {
guard let lastIndex = lines.indices.last else {
return
}
lines[lastIndex].points.append(position)
}
})
)
}
}
}
However, I am uncertain why the scrollview didn't work.
Have a great day!
Hi! To go to another view in SwiftUI, you can use NavigationStack! You also have to use NavigationLink(destination: AnotherView()) and then wrap the label in it (the Text). This way the text element becomes pressable, and when pressed, it'll take you to the next view, AnotherView()!.
struct ContentView: View {
var body: some View {
NavigationStack { //<-- Wrap your whole view into NavigationStack to enable the navigation to subviews
ScrollView{
VStack {
ForEach(0..<14) {value in
NavigationLink(destination: AnotherView(), label: { //<-- Wrap your content in a NavigationLink
Text("Test \(value)")
.padding(.vertical)
}) //<-- Closing bracket to NavigationLink
}
}
}
} //<-- Closing bracket to NavigationStack
}
}
struct AnotherView: View {
var body: some View {
Text("Another View")
}
}
The reason this doesn't work is you can't call a view from not in your view body and expect SwiftUI to show the view. The compiler throws a warning that says: "Result of AnotherView() initialiser is unused":
.onTapGesture {
print("scrollview-item tapped")
AnotherView() //<-- Result of AnotherView() initialiser is unused
}
Also, NavigationStack has to be used to enable navigation. Without NavigationStack and only using NavigationLink, the NavigationLink won't work.
Have a great day!
It seems I also have the same issue.. Hope this fixes. I also found a StackOverflow post mentioning the issue: https://stackoverflow.com/questions/77559646/swiftdata-cascade-deletion-rule-not-working
Weird, I tried your code and it worked in the simulator (iOS 17.2, Xcode 15.1). One thing I thought about was that if you have any view in your RandomTestingFeaturesApp.swift file that fights with your ContentView.
Like if you have this code:
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.padding() // <- padding which limits contentview to not reach all safe area
}
}
}
struct ContentView: View {
let mainColor = Color.green
var body: some View {
ZStack {
mainColor.ignoresSafeArea(.all)
Text("Hello world!")
.padding()
}
}
}
With and without padding in the TestApp app struct:
To sum, please check your main app struct in the RandomTestingFeaturesApp.swift file, and have a great day!
Hi, I experimented a little and thought why not taking { $0.id == detailID } directly instead of wrapping it in a string { $0.id == "($detailID)" } because I managed to find this error from your code: "Referencing operator function '==' on 'StringProtocol' requires that 'UUID' conform to 'StringProtocol'". (instead of the unhelpful "Failed to produce.." error).
However, I am not 100 percent sure this will fix, but I hope you can try it. Have a great day!
@Transfinite01, I was also confused about this because I saw a picture from the Xcode Cloud's overview page (https://developer.apple.com/xcode-cloud/) showing Backyard Birds tests.