How to use animation in iOS15?

I used animation in these codes, and there was warning like "'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead."

I am beginner, so please tell me how to fix it specifically.




struct ContentView: View {

    @State var image: Image?

    @State var isPicking = false

    var body: some View {

        ZStack {

            VStack {

                VStack {

                        Spacer()

                        image?

                            .resizable()

                            .scaledToFit()

                        Spacer()

                    }

                HStack {

                    Spacer()

                    Button(action: {

                        self.isPicking = true

                    }) {

                        Image(systemName: "camera")

                        Text("カメラ")

                    }.padding()

                }

            }

            if isPicking {

                ImagePicker()

                    .edgesIgnoringSafeArea(.all)

                    .transition(.move(edge: .bottom))

                    .animation(.easeInOut)

            }

        }

    }

}



struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}

Trying your code, but I miss ImagePicker definition to test any animation and validate the solution.

Could you please show complete code ?

But you could silence the warning:

                    .animation(.easeInOut(duration: 4), value: isPicking)

or simply

                    .animation(.easeInOut, value: isPicking)

Thank you for your answer! I could silence it. I put the rest of codes. Actually, I tried to make the simple app using a camera, but it crashed and I don't know why. If you don't mind, please tell me about that too.




struct ImagePicker: UIViewControllerRepresentable{

   

    func makeCoordinator() -> Coordinator {

      Coordinator(self)

    }

    

    func makeUIViewController(context: Context) ->

    UIImagePickerController{

        let picker = UIImagePickerController()

        picker.sourceType = .camera

        picker.delegate = context.coordinator

        return picker

    }

    

    func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {

    }



}



struct ImagePicker_Previews: PreviewProvider {

    static var previews: some View {

        ImagePicker()

    }

}

and here is about class Coordinator




class Coordinator: NSObject, UINavigationControllerDelegate,

UIImagePickerControllerDelegate{

    var parent: ImagePicker

    init(_ parent: ImagePicker){

        self.parent = parent

    }



 func imagePickerController(_ picker: UIImagePickerController,

                           didFinishPickingMediaWithInfo info:

                                       [UIImagePickerController.InfoKey: Any]){

    let uiImage = info[.originalImage] as! UIImage

    UIImageWriteToSavedPhotosAlbum(uiImage, nil, nil, nil)

}



func imagePickerControllerDidCancel(_ picker: UIImagePickerController){

}

}

I'd appreciate if you could answer these questions.

How to use animation in iOS15?
 
 
Q