From 1de65e2a511f258610c8c3d6f6940a4408f58a40 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 16 Aug 2016 17:38:18 -0400 Subject: [ios] Improve user location annotation performance (#6019) * [ios] Don't animate zoom-induced accuracy ring size changes Improves perceived and actual performance by eliminating the implicit animation that occurred when the accuracy ring changed size during zooms. This previously would pile up animations as the zoom changed, causing an unsightly wobbling effect. * [ios] Pre-calculate shadow paths for user dot and puck Performance enhancement suggested by https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide/ImprovingAnimationPerformance/ImprovingAnimationPerformance.html * [ios] Rasterize pulsating inner dot of user location annotation Supposed performance enhancement and also improves edge smoothness. --- platform/ios/src/MGLFaux3DUserLocationAnnotationView.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'platform/ios') diff --git a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m index ac0551430b..95a0084f9f 100644 --- a/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m +++ b/platform/ios/src/MGLFaux3DUserLocationAnnotationView.m @@ -148,6 +148,7 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck _puckDot.backgroundColor = [[UIColor whiteColor] CGColor]; _puckDot.shadowColor = [[UIColor blackColor] CGColor]; _puckDot.shadowOpacity = 0.25; + _puckDot.shadowPath = [[UIBezierPath bezierPathWithOvalInRect:_puckDot.bounds] CGPath]; if (self.mapView.camera.pitch) { @@ -291,6 +292,13 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck if (accuracyRingSize > MGLUserLocationAnnotationDotSize + 15) { _accuracyRingLayer.hidden = NO; + + // disable implicit animation of the accuracy ring, unless triggered by a change in accuracy + id shouldDisableActions = (_oldHorizontalAccuracy == self.userLocation.location.horizontalAccuracy) ? (id)kCFBooleanTrue : (id)kCFBooleanFalse; + + [CATransaction begin]; + [CATransaction setValue:shouldDisableActions forKey:kCATransactionDisableActions]; + _accuracyRingLayer.bounds = CGRectMake(0, 0, accuracyRingSize, accuracyRingSize); _accuracyRingLayer.cornerRadius = accuracyRingSize / 2; @@ -298,6 +306,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck _haloLayer.bounds = _accuracyRingLayer.bounds; _haloLayer.cornerRadius = _accuracyRingLayer.cornerRadius; _haloLayer.shouldRasterize = NO; + + [CATransaction commit]; } else { @@ -365,6 +375,7 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck _dotBorderLayer.backgroundColor = [[UIColor whiteColor] CGColor]; _dotBorderLayer.shadowColor = [[UIColor blackColor] CGColor]; _dotBorderLayer.shadowOpacity = 0.25; + _dotBorderLayer.shadowPath = [[UIBezierPath bezierPathWithOvalInRect:_dotBorderLayer.bounds] CGPath]; if (self.mapView.camera.pitch) { @@ -385,7 +396,6 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck { _dotLayer = [self circleLayerWithSize:MGLUserLocationAnnotationDotSize * 0.75]; _dotLayer.backgroundColor = [self.mapView.tintColor CGColor]; - _dotLayer.shouldRasterize = NO; // set defaults for the animations CAAnimationGroup *animationGroup = [self loopingAnimationGroupWithDuration:1.5]; -- cgit v1.2.1