I'm working on a proof of concept, and the goal I have is: To have an array of coordinates, and animate differently to each one.
Here is the following code I have:
.mapCameraKeyframeAnimator(trigger: startSequence) { camera in
KeyframeTrack(\MapCamera.centerCoordinate) {
for pin in viewModel.mapPins {
if pin == viewModel.mapPins.first {
CubicKeyframe(pin.coordinates, duration: 3)
} else {
CubicKeyframe(pin.coordinates, duration: 3)
}
}
}
KeyframeTrack(\MapCamera.heading) {
for pin in viewModel.mapPins {
if pin == viewModel.mapPins.first {
LinearKeyframe(camera.heading, duration: 1.5)
CubicKeyframe(camera.heading + 45, duration: 4)
} else {
LinearKeyframe(camera.heading, duration: 1.5)
CubicKeyframe(camera.heading + 45, duration: 4)
}
}
}
}
Now on the .heading keyframe, it throws the error: Underlying type for opaque result type 'some KeyframeTrackContent<Value>' could not be inferred from return expression. This only happens inside a for-loop and when there are multiple frames.
Figured it needs to return a KeyframeTrackContent object but it 1. doesn't have an initializer and 2. Using the builder static func throws an unknown error bug. If anyone is into mapkit and could help me out, much would be appreciated!
Edit: Please note that using Group, for-each, or any other type of view does not work as it needs to return KeyframeTrackContent