From aabb598b98ab2d560d509e73d905c7929e06415e Mon Sep 17 00:00:00 2001 From: Stefan Lage Date: Fri, 9 May 2014 18:55:13 +0200 Subject: [PATCH] Allow to animated or not the map in terms of behaviors --- SLParallaxController/SLParallaxController.h | 4 +++- SLParallaxController/SLParallaxController.m | 22 +++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/SLParallaxController/SLParallaxController.h b/SLParallaxController/SLParallaxController.h index e32d4c0..0e87d96 100644 --- a/SLParallaxController/SLParallaxController.h +++ b/SLParallaxController/SLParallaxController.h @@ -34,9 +34,11 @@ @property (nonatomic) float Y_tableViewOnBottom; @property (nonatomic) float latitudeUserUp; @property (nonatomic) float latitudeUserDown; +@property (nonatomic) BOOL regionAnimated; +@property (nonatomic) BOOL userLocationUpdateAnimated; // Move the map in terms of user location // @minLatitude : subtract to the current user's latitude to move it on Y axis in order to view it when the map move -- (void)zoomToUserLocation:(MKUserLocation *)userLocation minLatitude:(float)minLatitude; +- (void)zoomToUserLocation:(MKUserLocation *)userLocation minLatitude:(float)minLatitude animated:(BOOL)anim; @end diff --git a/SLParallaxController/SLParallaxController.m b/SLParallaxController/SLParallaxController.m index 00e0b22..6320364 100644 --- a/SLParallaxController/SLParallaxController.m +++ b/SLParallaxController/SLParallaxController.m @@ -76,6 +76,8 @@ -(void)setup{ _default_Y_mapView = DEFAULT_Y_OFFSET; _headerYOffSet = DEFAULT_Y_OFFSET; _heightMap = 1000.0f; + _regionAnimated = YES; + _userLocationUpdateAnimated = YES; } -(void)setupTableView{ @@ -148,7 +150,9 @@ -(void) openShutter{ self.isShutterOpen = YES; [self.tableView setScrollEnabled:NO]; // Center the user 's location - [self zoomToUserLocation:self.mapView.userLocation minLatitude:self.latitudeUserDown]; + [self zoomToUserLocation:self.mapView.userLocation + minLatitude:self.latitudeUserDown + animated:self.regionAnimated]; // Inform the delegate if([self.delegate respondsToSelector:@selector(didTableViewMoveDown)]){ @@ -172,7 +176,9 @@ -(void) closeShutter{ [self.tableView setScrollEnabled:YES]; [self.tableView.tableHeaderView addGestureRecognizer:self.tapMapViewGesture]; // Center the user 's location - [self zoomToUserLocation:self.mapView.userLocation minLatitude:self.latitudeUserUp]; + [self zoomToUserLocation:self.mapView.userLocation + minLatitude:self.latitudeUserUp + animated:self.regionAnimated]; // Inform the delegate if([self.delegate respondsToSelector:@selector(didTableViewMoveUp)]){ @@ -272,7 +278,7 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)ce #pragma mark - MapView Delegate -- (void)zoomToUserLocation:(MKUserLocation *)userLocation minLatitude:(float)minLatitude +- (void)zoomToUserLocation:(MKUserLocation *)userLocation minLatitude:(float)minLatitude animated:(BOOL)anim { if (!userLocation) return; @@ -283,14 +289,18 @@ - (void)zoomToUserLocation:(MKUserLocation *)userLocation minLatitude:(float)min region.span = MKCoordinateSpanMake(.05, .05); //Zoom distance region = [self.mapView regionThatFits:region]; [self.mapView setRegion:region - animated:YES]; + animated:anim]; } -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{ if(_isShutterOpen) - [self zoomToUserLocation:self.mapView.userLocation minLatitude:self.latitudeUserDown]; + [self zoomToUserLocation:self.mapView.userLocation + minLatitude:self.latitudeUserDown + animated:self.userLocationUpdateAnimated]; else - [self zoomToUserLocation:self.mapView.userLocation minLatitude:self.latitudeUserUp]; + [self zoomToUserLocation:self.mapView.userLocation + minLatitude:self.latitudeUserUp + animated:self.userLocationUpdateAnimated]; } #pragma mark - UIGestureRecognizerDelegate