[ios] Update frame size when changing dot/puck mode

- Keeps the same center point
- `updateFrameWithSize:` does not take CGSize because there is not yet
  support for non-square user location annotations
This commit is contained in:
Jason Wray
2016-04-25 16:19:47 -04:00
parent 0339639e3d
commit 8ce0fb4739

View File

@@ -181,6 +181,22 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
}
}
- (void)updateFrameWithSize:(CGFloat)size
{
CGSize newSize = CGSizeMake(size, size);
if (CGSizeEqualToSize(self.frame.size, newSize))
{
return;
}
// Update frame size, keeping the existing center point.
CGPoint oldCenter = self.center;
CGRect newFrame = self.frame;
newFrame.size = newSize;
[self setFrame:newFrame];
[self setCenter:oldCenter];
}
- (void)drawPuck
{
if ( ! _puckModeActivated)
@@ -193,6 +209,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
_haloLayer = nil;
_dotBorderLayer = nil;
_dotLayer = nil;
[self updateFrameWithSize:MGLUserLocationAnnotationPuckSize];
}
// background dot (white with black shadow)
@@ -268,6 +286,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck
_puckDot = nil;
_puckArrow = nil;
[self updateFrameWithSize:MGLUserLocationAnnotationDotSize];
}
BOOL showHeadingIndicator = _mapView.userTrackingMode == MGLUserTrackingModeFollowWithHeading;