I am working in a map application which renders a polyline over a map. I am having an issue when zooming, it keeps the previous polyline on the tile.
I have tried to force redrawing:
[self.mapView reloadInputViews];
[self.mapView.layer setNeedsDisplay];
[self.mapView setNeedsDisplay];
Also I tried to slow the zoom speed, but the issue is still in there:
[MKMapView animateWithDuration:2
delay:0
usingSpringWithDamping:0.6
initialSpringVelocity:10
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self.mapView setVisibleMapRect:unionRectThatFits
edgePadding:UIEdgeInsetsMake(20, 10, 20, 10)
animated:YES];
}
completion: nil];
Does anyone know about this?
I found the resolution to the problem here: How to refresh an MKOverlayRenderer when mapView change
So I added:
override var boundingMapRect: MKMapRect {
return MKMapRectWorld
}
To my MKPolyline & MKCircle subclass.
Related
I have a problem with my function.
[UIView animateWithDuration:5 animations:^{
//set end coordinates for marker = MKAnnotationPoint
[self.followDriverMarker setCoordinate:CLLocationCoordinate2DMake(latitde, longitude)];
//set end coordinate for camera/map
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(latitde, longitude) animated:NO];
}
completion:^(BOOL finished) {
if (finished) {
if (self.currentPosition < [self.followDriverList count] - 2) {
self.currentPosition++;
//start next one
[self runAnimation];
} else {
//animation is finished
//TODO
self.isAnimationRunning = NO;
}
}
}];
The function will look in a List if there are locations left. If so it will run again. That works. The only problem is. If the animation is running. There is no interaction possible with the mapView. The other problem is that i cannot find how to cancel,stop or remove my Animation.
If I put:
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(latitde, longitude) animated:NO];
inside the the completionBlock, I have interaction with map. But I don't want to do that because I want to animate it the same time. Also here I can't find a way to cancel the animation.
Please don't say removeAllAnimation. This is not working.
I believe this answers your question.
Basically you commit a new animation on the same target with a short duration. By setting the setAnimationBeginsFromCurrentState flag you prevent weird jumps.
I have around 500 pins I would like to display on a MKMapView.
However, when I call mapView.addAnnotations(places) (places being an array of MKAnnotation objects), the pins slowly drop one by one.
I would like to either :
drop all pins at once at load
cancel the drop animation altogether
Is this possible ?
You should set animatesDrop property of your MKAnnotationViews to NO(false)
By setting animation property to No will drop all the Pins at once on the MapView.
MKAnnotationView *annotationView =[[MKAnnotationView alloc]init];
annotationView.animatesDrop=FALSE;
You'll need to implement your own drop animation in the didAddAnnotationViews delegate method. You should also set animatesDrop to NO to avoid a possible double animation.
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)annotationViews
{
NSTimeInterval delayInterval = 0;
for (MKAnnotationView *annView in annotationViews)
{
CGRect endFrame = annView.frame;
annView.frame = CGRectOffset(endFrame, 0, -500);
[UIView animateWithDuration:0.125
delay:delayInterval
options:UIViewAnimationOptionAllowUserInteraction
animations:^{ annView.frame = endFrame; }
completion:NULL];
delayInterval += 0.0625;
}
}
I am using an animation technique to improve upon the zooming of user location. It essentially zooms out to the world view and then down to the local view. The zoom process itself works just fine but the map rendering doesn't look very good. Essentially during the zoom animation you see the grid cut in an out as the map itself renders. This is actually true of the "standard" map as well as the "Sat" or "Hybrid" maps.
I am not sure if this is a cache issue or just the rendering engine in conjunction with the phone's hardware not being fast enough? This occurs on the sim as well as on the device (an iPhone 5 in this case running ios 8.x). Any way to improve visual performance here?
MKCoordinateRegion worldRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, .5*METERS_PER_MILE, .5*METERS_PER_MILE);
[MKMapView animateWithDuration:3.0 animations:^{
[self.mapView setRegion:worldRegion animated:YES];
} completion:^(BOOL finished){
[MKMapView animateWithDuration:3.0 animations:^{
[self.mapView setRegion:viewRegion animated:YES];
}completion:^(BOOL finished) {
NSLog(#"Final complete");
}];
}];
I am coding in iOS.
I have an NSArray, which contains a few MKMapCameras. I want to display MKMapCameras from the array one after another.
I put a while loop and used [self.mapView setCamera:nextCamera animated:YES];
However, this is only showing the first and the last views. Everything in between is going too fast.
I want to slow down the movement of each camera. Is there a way to achieve it using CATransaction or using any other animation tricks. If so, could you please show me an example code?
Want to give an update... I tried below code. But it isn't working... Camera movements are fast as I mentioned earlier.
[CATransaction begin];
[CATransaction setAnimationDuration:5.5];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[CATransaction setCompletionBlock:^{
[self.mapView setCamera:nextCamera animated:YES];
}];
[CATransaction commit];
After fiddling with it a few hours, I figured out a way to make it work. Thought of sharing the same with everyone...
I made two changes. I replaced CATransaction with UIView's animation. I also removed Camera's default animation settings, which was conflicting with UIView's animation.
Below is the code.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:2.5];
self.mapView.camera = nextCamera;
[UIView commitAnimations];
According to the WWDC 'Putting MapKit in Perspective' video you should avoid any approach using completion handlers for animating map cameras in sequence. Rather you should set a delegate on your map view and listen for the regionDidChangeAnimated: call to trigger the next camera in your sequence. This way the speed of the camera movement can be controlled with animateWithDuration:
-(void)flyToLocation:(CLLocationCoordinate2D)toLocation {
CLLocationCoordinate2D startCoord = self.mapView.camera.centerCoordinate;
CLLocationCoordinate2D eye = CLLocationCoordinate2DMake(toLocation.latitude, toLocation.longitude);
MKMapCamera *upCam = [MKMapCamera cameraLookingAtCenterCoordinate:startCoord
fromEyeCoordinate:startCoord
eyeAltitude:80000];
MKMapCamera *turnCam = [MKMapCamera cameraLookingAtCenterCoordinate:toLocation
fromEyeCoordinate:startCoord
eyeAltitude:80000];
MKMapCamera *inCam = [MKMapCamera cameraLookingAtCenterCoordinate:toLocation
fromEyeCoordinate:eye
eyeAltitude:26000];
self.camerasArray = [NSMutableArray arrayWithObjects:upCam, turnCam, inCam, nil];
[self gotoNextCamera];
}
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
[self gotoNextCamera];
}
-(void)gotoNextCamera {
if (self.camerasArray.count == 0) {
return;
}
MKMapCamera *nextCam = [self.camerasArray firstObject];
[self.camerasArray removeObjectAtIndex:0];
[UIView animateWithDuration:3.0 animations:^{
self.mapView.camera = nextCam;
}];
}
I have something like 30 annotations in my map and I want speed up the dropping animation.
Is it possible speed up the drop of annotation in MKMapView or drop all of them at once?
You'll need to implement your own drop animation in the didAddAnnotationViews delegate method. You should also set animatesDrop to NO to avoid a possible double animation.
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)annotationViews
{
NSTimeInterval delayInterval = 0;
for (MKAnnotationView *annView in annotationViews)
{
CGRect endFrame = annView.frame;
annView.frame = CGRectOffset(endFrame, 0, -500);
[UIView animateWithDuration:0.125
delay:delayInterval
options:UIViewAnimationOptionAllowUserInteraction
animations:^{ annView.frame = endFrame; }
completion:NULL];
delayInterval += 0.0625;
}
}
This drops the annotations at a rate you specify.
To drop them all at once, hard-code the delay parameter to 0.0 instead of the incrementing delayInterval.