ios - Disable adding annotations to mapView while animating its frame -
i animating frame of mapview uiview animation:
[uiview animatewithduration:0.25f animations:^{ self.mapview.frame = frame; } completion:nil]; } while expanding mapview above see mapview adding misplaced annotations until animation over. when animation finished misplaced annotations disappears.
the calls follows when expand map:
animatewithduration begin mapview:regionwillchangeanimated mapview:didaddannotationviews mapview:regiondidchangeanimated animatewithduration completeno problem when minimise map because mapview:didaddannotationviews isn't called.
can somehow disable mapviews regionwillchange while animating?
before animation:
halfway in animation. seeing lot of missplaced annotations.
animation done. missplaced annotations gone.
as temporary solution can suggest following: 1. create uiimageview screenshot of mapview before changing it's frame 2. add together imageview subview parent view , hide mapview. 3. animate both: imageview , mapview changing it's frames. 4. in completion block of animation unhide mapview , remove imageview.
something 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(); homecoming 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 animate mapview, because hidden. alter 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 temporary solution until find right way solve problem.
ios objective-c annotations mkmapview
No comments:
Post a Comment