I am animating the frame of my mapView with a UIView animation:
[UIView animateWithDuration:0.25f animations:^{
self.mapView.frame = frame;
} completion:nil];
}
While expanding the mapView with the above I see that mapView is adding misplaced annotations until the animation is over. When the animation is finished the misplaced annotations disappears.
The calls are as follows when I expand the map:
No problem when I minimise the map probably because the mapView:didAddAnnotationViews isn't called.
Can I somehow disable mapviews regionWillChange while animating?
Before animation:
Halfway in the animation. Seeing a lot of missplaced annotations.
Animation is done. All missplaced annotations is gone.
As a temporary solution I can suggest you to do following:
1. Make a UIImageView with screenShot of your mapView before changing it's frame
2. Add that imageView as subView to your parent view and hide your mapView.
3. animate both: imageView and mapView with changing it's frames.
4. In completion block of animation unhide your mapView and remove imageView.
Something like this:
- (UIImage *)imageFromView:(UIView *) view
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]);
} else {
UIGraphicsBeginImageContext(view.frame.size);
}
[view.layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)foo
{
UIImageView *mapScreenShotView = [[UIImageView alloc] initWithImage:[self imageFromView:self.mapView]];
mapScreenShotView.frame = self.mapView.frame;
[self.mapView.superview addSubview:mapScreenShotView];
self.mapView.hidden = YES;
CGRect frame = self.mapView.frame;
frame.origin = ...
frame.size = ...
// here no more need to animate mapView, because currently its hidden. So we will change it's frame in outside of animation block.
self.mapView.frame = frame;
[UIView animateWithDuration:0.25f animations:^{
mapScreenShotView.frame = frame;
} completion:^{
self.mapView.hidden = NO;
[mapScreenShotView removeFromSuperview];
}];
}
Use this temporary solution until you find a right way to solve that problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With