[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.
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user