Post

Replies

Boosts

Views

Activity

SwiftUI Transition not respecting Parent animation
This might be a known limitation already, but I have an issue that when I try to transition in a child view into an animated parent view, the child view does not respect it's parent animation. Both animations are controlled by 1 State variable. When this one changes, it should trigger both the position of the parent (via een offset modifier), as well as transition in a child view. However, the child view transitions in on the end position (so in my example, it only fades in), instead of also moving with the parent during the animation. struct ContentView: View {     @State private var isShowing = false     var body: some View {         HStack {             Text("Hello")                 .padding()                 .background(Color.blue)             if isShowing {                 Text("World")                     .padding()                     .background(Color.red)                     .transition(.opacity)             }         }         .background(Color.orange)         .offset(y: isShowing ? 100 : 0)         .onTapGesture {             withAnimation {                 isShowing.toggle()             }         }     } }
1
1
1.6k
Jan ’21
SwiftUI: withAnimation in onChange not working
I am trying to create an animation that is triggered by a change in a different value. However, the animation is not working. The view just "pops-up" immediately instead of using it's transition. struct ContentView: View {     @State private var count = 0     @State private var isShowing = false     var body: some View {         VStack {             if isShowing {                 Text("SHOWING")                     .transition(.scale)             }             Button("Increase") {                 count += 1             }         }             .frame(width: 200, height: 200)             .onChange(of: count, perform: { (count) in                 withAnimation {                     isShowing.toggle()                 }             })     } }
2
0
2.9k
Jan ’21
MKMarkerAnnotationView being clipped
I am trying to create a map snapshot, using MKMapSnapshotter that includes a MKMarkerAnnotationView. The issue I am facing is that the MKMarkerAnnotationView is being clipped. I can see that the frame of my MKMarkerAnnotationView is 28*28, which seems to be too small. My code: if let image = snapshot?.image { /* Create the annotation */     let annotation = MKPointAnnotation()     annotation.coordinate = center /* Create the annotation view */     let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: nil)     annotationView.glyphImage = UIImage(named: "mappin")     annotationView.isSelected = true /* annotationView.frame would show the width and height being 28 */ /* Start the context */     UIGraphicsBeginImageContextWithOptions(image.size, true, image.scale) /* Draw the image from the MKMapSnapshotter in the context */     image.draw(at: CGPoint(x: 0, y: 0)) /* Define the rect where the Annotation View should be rendered in */     let rect = CGRect(x: snapshot!.point(for: center).x, y: snapshot!.point(for: center).y, width: annotationView.frame.width, height: annotationView.frame.height) /* Draw the Annotation View in the context */     annotationView.drawHierarchy(in: rect, afterScreenUpdates: true)     let finalImage = UIGraphicsGetImageFromCurrentImageContext()     UIGraphicsEndImageContext() }
1
0
1.1k
Jul ’20