[ASMapNode] Some improvements to layout logic and snapshot triggering.

This commit is contained in:
Scott Goodson
2016-01-23 20:12:45 -08:00
parent 570d3e202f
commit 82f7956bf9
2 changed files with 28 additions and 5 deletions

View File

@@ -36,7 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign, getter=isLiveMap) BOOL liveMap; @property (nonatomic, assign, getter=isLiveMap) BOOL liveMap;
/** /**
@abstract Whether ASMapNode should automatically request a new map snapshot to correspond to the new node size. Defaults to YES. @abstract Whether ASMapNode should automatically request a new map snapshot to correspond to the new node size.
@default Default value is YES.
@discussion If mapSize is set then this will be set to NO, since the size will be the same in all orientations. @discussion If mapSize is set then this will be set to NO, since the size will be the same in all orientations.
*/ */
@property (nonatomic, assign) BOOL needsMapReloadOnBoundsChange; @property (nonatomic, assign) BOOL needsMapReloadOnBoundsChange;

View File

@@ -117,7 +117,10 @@
if (!_options) { if (!_options) {
_options = [[MKMapSnapshotOptions alloc] init]; _options = [[MKMapSnapshotOptions alloc] init];
_options.region = MKCoordinateRegionForMapRect(MKMapRectWorld); _options.region = MKCoordinateRegionForMapRect(MKMapRectWorld);
_options.size = self.calculatedSize; CGSize calculatedSize = self.calculatedSize;
if (!CGSizeEqualToSize(calculatedSize, CGSizeZero)) {
_options.size = calculatedSize;
}
} }
return _options; return _options;
} }
@@ -250,6 +253,24 @@
} }
#pragma mark - Layout #pragma mark - Layout
- (void)setSnapshotSizeIfNeeded:(CGSize)snapshotSize
{
if (!CGSizeEqualToSize(self.options.size, snapshotSize)) {
_options.size = snapshotSize;
[self resetSnapshotter];
}
}
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
CGSize size = self.preferredFrameSize;
if (CGSizeEqualToSize(size, CGSizeZero)) {
size = constrainedSize;
}
[self setSnapshotSizeIfNeeded:size];
return constrainedSize;
}
// Layout isn't usually needed in the box model, but since we are making use of MKMapView this is preferred. // Layout isn't usually needed in the box model, but since we are making use of MKMapView this is preferred.
- (void)layout - (void)layout
{ {
@@ -258,9 +279,10 @@
_mapView.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height); _mapView.frame = CGRectMake(0.0f, 0.0f, self.calculatedSize.width, self.calculatedSize.height);
} else { } else {
// If our bounds.size is different from our current snapshot size, then let's request a new image from MKMapSnapshotter. // If our bounds.size is different from our current snapshot size, then let's request a new image from MKMapSnapshotter.
if (!CGSizeEqualToSize(_options.size, self.bounds.size) && _needsMapReloadOnBoundsChange) { if (_needsMapReloadOnBoundsChange) {
_options.size = self.bounds.size; [self setSnapshotSizeIfNeeded:self.bounds.size];
[self resetSnapshotter]; // FIXME: Adding a check for FetchData here seems to cause intermittent map load failures, but shouldn't.
// if (ASInterfaceStateIncludesFetchData(self.interfaceState)) {
[self takeSnapshot]; [self takeSnapshot];
} }
} }