Created
August 17, 2011 11:58
Revisions
-
digdog revised this gist
Nov 22, 2009 . 1 changed file with 17 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,13 +10,13 @@ @implementation DDAnnotationView - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { if ((self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier])) { self.enabled = YES; self.canShowCallout = YES; self.multipleTouchEnabled = NO; self.animatesDrop = YES; } return self; } #pragma mark - @@ -26,7 +26,7 @@ - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // The view is configured for single touches only. UITouch* aTouch = [touches anyObject]; _startLocation = [aTouch locationInView:[self superview]]; _originalCenter = self.center; @@ -40,20 +40,20 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint newLocation = [aTouch locationInView:[self superview]]; CGPoint newCenter; // If the user's finger moved more than 5 pixels, begin the drag. if ((abs(newLocation.x - _startLocation.x) > 5.0) || (abs(newLocation.y - _startLocation.y) > 5.0)) { _isMoving = YES; } // If dragging has begun, adjust the position of the view. if (_mapView && _isMoving) { newCenter.x = _originalCenter.x + (newLocation.x - _startLocation.x); newCenter.y = _originalCenter.y + (newLocation.y - _startLocation.y); self.center = newCenter; } else { // Let the parent class handle it. [super touchesMoved:touches withEvent:event]; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { @@ -70,9 +70,9 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { _startLocation = CGPointZero; _originalCenter = CGPointZero; _isMoving = NO; } else { [super touchesEnded:touches withEvent:event]; } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { @@ -87,7 +87,7 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { _isMoving = NO; } else { [super touchesCancelled:touches withEvent:event]; } } @end -
digdog revised this gist
Nov 22, 2009 . 1 changed file with 21 additions and 38 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,11 @@ #import "DDAnnotationView.h" #import "DDAnnotation.h" #pragma mark - #pragma mark DDAnnotationView implementation @implementation DDAnnotationView @synthesize mapView = _mapView; - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { @@ -24,14 +14,7 @@ - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString self.enabled = YES; self.canShowCallout = YES; self.multipleTouchEnabled = NO; self.animatesDrop = YES; } return self; } @@ -45,8 +28,8 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // The view is configured for single touches only. UITouch* aTouch = [touches anyObject]; _startLocation = [aTouch locationInView:[self superview]]; _originalCenter = self.center; [super touchesBegan:touches withEvent:event]; } @@ -58,14 +41,14 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint newCenter; // If the user's finger moved more than 5 pixels, begin the drag. if ((abs(newLocation.x - _startLocation.x) > 5.0) || (abs(newLocation.y - _startLocation.y) > 5.0)) { _isMoving = YES; } // If dragging has begun, adjust the position of the view. if (_mapView && _isMoving) { newCenter.x = _originalCenter.x + (newLocation.x - _startLocation.x); newCenter.y = _originalCenter.y + (newLocation.y - _startLocation.y); self.center = newCenter; } else { // Let the parent class handle it. @@ -74,37 +57,37 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (_mapView && _isMoving) { // Update the map coordinate to reflect the new position. CGPoint newCenter = self.center; DDAnnotation* theAnnotation = (DDAnnotation *)self.annotation; CLLocationCoordinate2D newCoordinate = [_mapView convertPoint:newCenter toCoordinateFromView:self.superview]; [theAnnotation changeCoordinate:newCoordinate]; // Clean up the state information. _startLocation = CGPointZero; _originalCenter = CGPointZero; _isMoving = NO; } else { [super touchesEnded:touches withEvent:event]; } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { if (_mapView && _isMoving) { // Move the view back to its starting point. self.center = _originalCenter; // Clean up the state information. _startLocation = CGPointZero; _originalCenter = CGPointZero; _isMoving = NO; } else { [super touchesCancelled:touches withEvent:event]; } } @end -
digdog revised this gist
Aug 2, 2009 . 1 changed file with 27 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,21 @@ #import "DDAnnotationView.h" #import "DDAnnotation.h" @interface DDAnnotationView () @property (nonatomic, assign) BOOL isMoving; @property (nonatomic, assign) CGPoint startLocation; @property (nonatomic, assign) CGPoint originalCenter; @end #pragma mark - #pragma mark DDAnnotationView implementation @implementation DDAnnotationView @synthesize isMoving = _isMoving; @synthesize startLocation = _startLocation; @synthesize originalCenter = _originalCenter; @synthesize mapView = _mapView; - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { @@ -35,8 +45,8 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // The view is configured for single touches only. UITouch* aTouch = [touches anyObject]; self.startLocation = [aTouch locationInView:[self superview]]; self.originalCenter = self.center; [super touchesBegan:touches withEvent:event]; } @@ -48,14 +58,14 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint newCenter; // If the user's finger moved more than 5 pixels, begin the drag. if ((abs(newLocation.x - self.startLocation.x) > 5.0) || (abs(newLocation.y - self.startLocation.y) > 5.0)) { self.isMoving = YES; } // If dragging has begun, adjust the position of the view. if (self.isMoving) { newCenter.x = self.originalCenter.x + (newLocation.x - self.startLocation.x); newCenter.y = self.originalCenter.y + (newLocation.y - self.startLocation.y); self.center = newCenter; } else { // Let the parent class handle it. @@ -65,33 +75,33 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (self.isMoving) { // Update the map coordinate to reflect the new position. CGPoint newCenter = self.center; DDAnnotation* theAnnotation = (DDAnnotation *)self.annotation; CLLocationCoordinate2D newCoordinate = [self.mapView convertPoint:newCenter toCoordinateFromView:self.superview]; [theAnnotation changeCoordinate:newCoordinate]; // Clean up the state information. self.startLocation = CGPointZero; self.originalCenter = CGPointZero; self.isMoving = NO; } else { [super touchesEnded:touches withEvent:event]; } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { if (self.isMoving) { // Move the view back to its starting point. self.center = self.originalCenter; // Clean up the state information. self.startLocation = CGPointZero; self.originalCenter = CGPointZero; self.isMoving = NO; } else { [super touchesCancelled:touches withEvent:event]; } -
digdog created this gist
Jul 25, 2009 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,100 @@ #import "DDAnnotationView.h" #import "DDAnnotation.h" #pragma mark - #pragma mark DDAnnotationView implementation @implementation DDAnnotationView @synthesize mapView = _mapView; - (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) { self.enabled = YES; self.canShowCallout = YES; self.multipleTouchEnabled = NO; self.animatesDrop = YES; UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"digdog.png"]]; self.leftCalloutAccessoryView = leftIconView; [leftIconView release]; UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; self.rightCalloutAccessoryView = rightButton; } return self; } #pragma mark - #pragma mark Handling events // Reference: iPhone Application Programming Guide > Device Support > Displaying Maps and Annotations > Displaying Annotations > Handling Events in an Annotation View - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // The view is configured for single touches only. UITouch* aTouch = [touches anyObject]; _startLocation = [aTouch locationInView:[self superview]]; _originalCenter = self.center; [super touchesBegan:touches withEvent:event]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* aTouch = [touches anyObject]; CGPoint newLocation = [aTouch locationInView:[self superview]]; CGPoint newCenter; // If the user's finger moved more than 5 pixels, begin the drag. if ((abs(newLocation.x - _startLocation.x) > 5.0) || (abs(newLocation.y - _startLocation.y) > 5.0)) { _isMoving = YES; } // If dragging has begun, adjust the position of the view. if (_isMoving) { newCenter.x = _originalCenter.x + (newLocation.x - _startLocation.x); newCenter.y = _originalCenter.y + (newLocation.y - _startLocation.y); self.center = newCenter; } else { // Let the parent class handle it. [super touchesMoved:touches withEvent:event]; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (_isMoving) { // Update the map coordinate to reflect the new position. CGPoint newCenter = self.center; DDAnnotation* theAnnotation = (DDAnnotation *)self.annotation; CLLocationCoordinate2D newCoordinate = [_mapView convertPoint:newCenter toCoordinateFromView:self.superview]; [theAnnotation changeCoordinate:newCoordinate]; // Clean up the state information. _startLocation = CGPointZero; _originalCenter = CGPointZero; _isMoving = NO; } else { [super touchesEnded:touches withEvent:event]; } } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { if (_isMoving) { // Move the view back to its starting point. self.center = _originalCenter; // Clean up the state information. _startLocation = CGPointZero; _originalCenter = CGPointZero; _isMoving = NO; } else { [super touchesCancelled:touches withEvent:event]; } } @end