Skip to content

Commit

Permalink
Allow to animated or not the map in terms of behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanLage committed May 9, 2014
1 parent bae692f commit aabb598
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion SLParallaxController/SLParallaxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 16 additions & 6 deletions SLParallaxController/SLParallaxController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)]){
Expand All @@ -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)]){
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit aabb598

Please sign in to comment.