From the reference: https://developer.apple.com/videos/play/wwdc2020/10652/. Dismiss the picker inside didFinishPicking function. The below code will dismiss the picker when the cancel button is pressed.
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
dismiss(animated: true)
}