diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index 0ad3d10..96e0e73 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -9,6 +9,12 @@ /* Begin PBXBuildFile section */ 07DDEB3EBEEC4C6FAF715BF1 /* libPods-DemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 98DB4ADA533041DD9D9E7647 /* libPods-DemoTests.a */; }; 273E9EE865984F44A8AF2A9D /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2957D8BD1FB4630AD6F922F /* libPods.a */; }; + 3C9F354518CA838600EA1F22 /* NAMasterViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354418CA838600EA1F22 /* NAMasterViewControllerTests.m */; }; + 3C9F354718CA862100EA1F22 /* NABasicDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354618CA862100EA1F22 /* NABasicDemoViewControllerTests.m */; }; + 3C9F354918CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354818CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m */; }; + 3C9F354B18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354A18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m */; }; + 3C9F354E18CA922C00EA1F22 /* NAPlainDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354D18CA922C00EA1F22 /* NAPlainDemoViewController.m */; }; + 3C9F355018CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354F18CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m */; }; 3CB0E6D718C8B9E2009CE8DB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */; }; 3CB0E6D918C8B9E2009CE8DB /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D818C8B9E2009CE8DB /* CoreGraphics.framework */; }; 3CB0E6DB18C8B9E2009CE8DB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6DA18C8B9E2009CE8DB /* UIKit.framework */; }; @@ -19,7 +25,6 @@ 3CB0E6F718C8B9E2009CE8DB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */; }; 3CB0E6F818C8B9E3009CE8DB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6DA18C8B9E2009CE8DB /* UIKit.framework */; }; 3CB0E70018C8B9E3009CE8DB /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3CB0E6FE18C8B9E3009CE8DB /* InfoPlist.strings */; }; - 3CB0E70218C8B9E3009CE8DB /* NAMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E70118C8B9E3009CE8DB /* NAMapViewTests.m */; }; 3CB0E71B18C8BB08009CE8DB /* NAAnimatedDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E70C18C8BB08009CE8DB /* NAAnimatedDemoViewController.m */; }; 3CB0E71C18C8BB08009CE8DB /* NAAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E70E18C8BB08009CE8DB /* NAAppDelegate.m */; }; 3CB0E71D18C8BB08009CE8DB /* NABasicDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E71018C8BB08009CE8DB /* NABasicDemoViewController.m */; }; @@ -30,6 +35,7 @@ 3CB0E72218C8BB08009CE8DB /* NAMasterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E71818C8BB08009CE8DB /* NAMasterViewController.m */; }; 3CB0E72718C8BC0C009CE8DB /* australia.png in Resources */ = {isa = PBXBuildFile; fileRef = 3CB0E72618C8BC0C009CE8DB /* australia.png */; }; 3CB0E72A18C8BC62009CE8DB /* NAMasterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3CB0E72818C8BC62009CE8DB /* NAMasterViewController.xib */; }; + 3CB0E72F18C8C9A4009CE8DB /* NAMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E72E18C8C9A4009CE8DB /* NAMapViewTests.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -43,6 +49,13 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 3C9F354418CA838600EA1F22 /* NAMasterViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAMasterViewControllerTests.m; sourceTree = ""; }; + 3C9F354618CA862100EA1F22 /* NABasicDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NABasicDemoViewControllerTests.m; sourceTree = ""; }; + 3C9F354818CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAInteractiveDemoViewControllerTests.m; sourceTree = ""; }; + 3C9F354A18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NALoadViaNIBDemoViewControllerTests.m; sourceTree = ""; }; + 3C9F354C18CA922C00EA1F22 /* NAPlainDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NAPlainDemoViewController.h; sourceTree = ""; }; + 3C9F354D18CA922C00EA1F22 /* NAPlainDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAPlainDemoViewController.m; sourceTree = ""; }; + 3C9F354F18CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAPlainDemoViewControllerTests.m; sourceTree = ""; }; 3CB0E6D318C8B9E2009CE8DB /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 3CB0E6D818C8B9E2009CE8DB /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -56,7 +69,6 @@ 3CB0E6F518C8B9E2009CE8DB /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 3CB0E6FD18C8B9E3009CE8DB /* DemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "DemoTests-Info.plist"; sourceTree = ""; }; 3CB0E6FF18C8B9E3009CE8DB /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - 3CB0E70118C8B9E3009CE8DB /* NAMapViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NAMapViewTests.m; sourceTree = ""; }; 3CB0E70B18C8BB08009CE8DB /* NAAnimatedDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NAAnimatedDemoViewController.h; sourceTree = ""; }; 3CB0E70C18C8BB08009CE8DB /* NAAnimatedDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAAnimatedDemoViewController.m; sourceTree = ""; }; 3CB0E70D18C8BB08009CE8DB /* NAAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NAAppDelegate.h; sourceTree = ""; }; @@ -74,6 +86,7 @@ 3CB0E72618C8BC0C009CE8DB /* australia.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = australia.png; sourceTree = ""; }; 3CB0E72918C8BC62009CE8DB /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/NAMasterViewController.xib; sourceTree = ""; }; 3CB0E72B18C8BD61009CE8DB /* DemoTests-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DemoTests-Prefix.pch"; sourceTree = ""; }; + 3CB0E72E18C8C9A4009CE8DB /* NAMapViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAMapViewTests.m; sourceTree = ""; }; 93B37F17EB6B492D83AB25A2 /* Pods-DemoTests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoTests.xcconfig"; path = "Pods/Pods-DemoTests.xcconfig"; sourceTree = ""; }; 98DB4ADA533041DD9D9E7647 /* libPods-DemoTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-DemoTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; BD0E280B71AE47E499695C40 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; @@ -161,6 +174,8 @@ 3CB0E71818C8BB08009CE8DB /* NAMasterViewController.m */, 3CB0E6EE18C8B9E2009CE8DB /* Images.xcassets */, 3CB0E6DD18C8B9E2009CE8DB /* Supporting Files */, + 3C9F354C18CA922C00EA1F22 /* NAPlainDemoViewController.h */, + 3C9F354D18CA922C00EA1F22 /* NAPlainDemoViewController.m */, ); path = Demo; sourceTree = ""; @@ -179,8 +194,13 @@ 3CB0E6FB18C8B9E3009CE8DB /* DemoTests */ = { isa = PBXGroup; children = ( - 3CB0E70118C8B9E3009CE8DB /* NAMapViewTests.m */, + 3CB0E72E18C8C9A4009CE8DB /* NAMapViewTests.m */, 3CB0E6FC18C8B9E3009CE8DB /* Supporting Files */, + 3C9F354418CA838600EA1F22 /* NAMasterViewControllerTests.m */, + 3C9F354618CA862100EA1F22 /* NABasicDemoViewControllerTests.m */, + 3C9F354818CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m */, + 3C9F354A18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m */, + 3C9F354F18CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m */, ); path = DemoTests; sourceTree = ""; @@ -368,6 +388,7 @@ 3CB0E71E18C8BB08009CE8DB /* NAInteractiveDemoViewController.m in Sources */, 3CB0E71C18C8BB08009CE8DB /* NAAppDelegate.m in Sources */, 3CB0E71B18C8BB08009CE8DB /* NAAnimatedDemoViewController.m in Sources */, + 3C9F354E18CA922C00EA1F22 /* NAPlainDemoViewController.m in Sources */, 3CB0E72018C8BB08009CE8DB /* NALoadViaNIBDemoViewController.m in Sources */, 3CB0E71D18C8BB08009CE8DB /* NABasicDemoViewController.m in Sources */, ); @@ -377,7 +398,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 3CB0E70218C8B9E3009CE8DB /* NAMapViewTests.m in Sources */, + 3C9F355018CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m in Sources */, + 3CB0E72F18C8C9A4009CE8DB /* NAMapViewTests.m in Sources */, + 3C9F354918CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m in Sources */, + 3C9F354718CA862100EA1F22 /* NABasicDemoViewControllerTests.m in Sources */, + 3C9F354518CA838600EA1F22 /* NAMasterViewControllerTests.m in Sources */, + 3C9F354B18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -533,6 +559,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "DemoTests/DemoTests-Prefix.pch"; GCC_PREPROCESSOR_DEFINITIONS = ( + "FB_REFERENCE_IMAGE_DIR=\"\\\"$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages\\\"\"", "DEBUG=1", "$(inherited)", ); @@ -556,6 +583,7 @@ ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "DemoTests/DemoTests-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ""; INFOPLIST_FILE = "DemoTests/DemoTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; diff --git a/Demo/Demo/NAAnimatedDemoViewController.m b/Demo/Demo/NAAnimatedDemoViewController.m index 803e1bb..1d35162 100644 --- a/Demo/Demo/NAAnimatedDemoViewController.m +++ b/Demo/Demo/NAAnimatedDemoViewController.m @@ -8,45 +8,39 @@ #import "NAAnimatedDemoViewController.h" #import "NAMapView.h" -#import "NAAnnotation.h" - - +#import "NAPinAnnotationMapView.h" +#import "NAPinAnnotation.h" @implementation NAAnimatedDemoViewController - - (void)viewDidLoad { [super viewDidLoad]; - - NAMapView *mapView = [[NAMapView alloc] initWithFrame:self.view.bounds]; - + + NAMapView *mapView = [[NAPinAnnotationMapView alloc] initWithFrame:self.view.bounds]; + mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f]; mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [mapView displayMap:[UIImage imageNamed:@"australia"]]; - + mapView.minimumZoomScale = 0.5f; mapView.maximumZoomScale = 1.5f; - + [self.view addSubview:mapView]; - - NAAnnotation *a0 = [NAAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)]; - NAAnnotation *a1 = [NAAnnotation annotationWithPoint:CGPointMake(130.0f, 340.0f)]; - NAAnnotation *a2 = [NAAnnotation annotationWithPoint:CGPointMake(200.0f, 311.0f)]; - NAAnnotation *a3 = [NAAnnotation annotationWithPoint:CGPointMake(308.0f, 304.0f)]; - NAAnnotation *a4 = [NAAnnotation annotationWithPoint:CGPointMake(404.0f, 302.0f)]; - NAAnnotation *a5 = [NAAnnotation annotationWithPoint:CGPointMake(472.0f, 367.0f)]; - NAAnnotation *a6 = [NAAnnotation annotationWithPoint:CGPointMake(530.0f, 422.0f)]; - NAAnnotation *a7 = [NAAnnotation annotationWithPoint:CGPointMake(541.0f, 488.0f)]; - - NSArray *annotations = [NSArray arrayWithObjects:a0, a1, a2, a3, a4, a5, a6, a7, nil]; - - [mapView addAnnotations:annotations animated:YES]; -} + NAPinAnnotation *a0 = [NAPinAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)]; + NAPinAnnotation *a1 = [NAPinAnnotation annotationWithPoint:CGPointMake(130.0f, 340.0f)]; + NAPinAnnotation *a2 = [NAPinAnnotation annotationWithPoint:CGPointMake(200.0f, 311.0f)]; + NAPinAnnotation *a3 = [NAPinAnnotation annotationWithPoint:CGPointMake(308.0f, 304.0f)]; + NAPinAnnotation *a4 = [NAPinAnnotation annotationWithPoint:CGPointMake(404.0f, 302.0f)]; + NAPinAnnotation *a5 = [NAPinAnnotation annotationWithPoint:CGPointMake(472.0f, 367.0f)]; + NAPinAnnotation *a6 = [NAPinAnnotation annotationWithPoint:CGPointMake(530.0f, 422.0f)]; + NAPinAnnotation *a7 = [NAPinAnnotation annotationWithPoint:CGPointMake(541.0f, 488.0f)]; + NSArray *annotations = [NSArray arrayWithObjects:a0, a1, a2, a3, a4, a5, a6, a7, nil]; + [mapView addAnnotations:annotations animated:YES]; +} @end diff --git a/Demo/Demo/NABasicDemoViewController.h b/Demo/Demo/NABasicDemoViewController.h index 88ada19..353ee79 100644 --- a/Demo/Demo/NABasicDemoViewController.h +++ b/Demo/Demo/NABasicDemoViewController.h @@ -9,5 +9,5 @@ #import @interface NABasicDemoViewController : UIViewController - +@property(nonatomic, readonly) NSArray *pins; @end diff --git a/Demo/Demo/NABasicDemoViewController.m b/Demo/Demo/NABasicDemoViewController.m index 61c6617..9690686 100644 --- a/Demo/Demo/NABasicDemoViewController.m +++ b/Demo/Demo/NABasicDemoViewController.m @@ -8,7 +8,8 @@ #import "NABasicDemoViewController.h" #import "NAMapView.h" -#import "NAAnnotation.h" +#import "NAPinAnnotationMapView.h" +#import "NAPinAnnotation.h" @interface NABasicDemoViewController () @@ -28,8 +29,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil - (void)viewDidLoad { [super viewDidLoad]; - - NAMapView *mapView = [[NAMapView alloc] initWithFrame:self.view.bounds]; + + NSMutableArray *pins = [NSMutableArray array]; + NAMapView *mapView = [[NAPinAnnotationMapView alloc] initWithFrame:self.view.bounds]; mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f]; mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; @@ -41,27 +43,31 @@ - (void)viewDidLoad [self.view addSubview:mapView]; - NAAnnotation *melbourne = [NAAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)]; - melbourne.title = @"Melbourne"; - melbourne.subtitle = @"I have a subtitle"; - melbourne.color = NAPinColorGreen; + NAPinAnnotation *melbourne = [NAPinAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)]; + melbourne.title = @"Melbourne"; + melbourne.subtitle = @"I have a subtitle"; + melbourne.color = NAPinColorGreen; [mapView addAnnotation:melbourne animated:NO]; + [pins addObject:melbourne]; - NAAnnotation * perth = [NAAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)]; - perth.title = @"Perth"; - perth.subtitle = @"I have a button"; + NAPinAnnotation * perth = [NAPinAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)]; + perth.title = @"Perth"; + perth.subtitle = @"I have a button"; perth.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; - perth.color = NAPinColorRed; + perth.color = NAPinColorRed; [mapView addAnnotation:perth animated:YES]; + [pins addObject:perth]; - NAAnnotation * brisbane = [NAAnnotation annotationWithPoint:CGPointMake(679.0f, 302.0f)]; - brisbane.title = @"Brisbane"; - brisbane.color = NAPinColorPurple; + NAPinAnnotation * brisbane = [NAPinAnnotation annotationWithPoint:CGPointMake(679.0f, 302.0f)]; + brisbane.title = @"Brisbane"; + brisbane.color = NAPinColorPurple; [mapView addAnnotation:brisbane animated:NO]; - + [pins addObject:brisbane]; + + _pins = pins; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation diff --git a/Demo/Demo/NAInteractiveDemoViewController.h b/Demo/Demo/NAInteractiveDemoViewController.h index 06a53e1..5188a39 100644 --- a/Demo/Demo/NAInteractiveDemoViewController.h +++ b/Demo/Demo/NAInteractiveDemoViewController.h @@ -8,13 +8,18 @@ #import #import "NAMapView.h" +#import "NAPinAnnotation.h" @interface NAInteractiveDemoViewController : UIViewController @property (nonatomic, weak) IBOutlet NAMapView *mapView; -(IBAction)addPin:(id)sender; +-(void)addPinAt:(CGPoint)point withColor:(NAPinColor)color; + -(IBAction)removePin:(id)sender; + -(IBAction)selectRandom:(id)sender; +-(void)selectPinAt:(NSInteger)index; @end diff --git a/Demo/Demo/NAInteractiveDemoViewController.m b/Demo/Demo/NAInteractiveDemoViewController.m index 01de13f..c1059d5 100644 --- a/Demo/Demo/NAInteractiveDemoViewController.m +++ b/Demo/Demo/NAInteractiveDemoViewController.m @@ -7,10 +7,11 @@ // #import "NAInteractiveDemoViewController.h" +#import "NAPinAnnotation.h" @interface NAInteractiveDemoViewController (){ int _count; - NAAnnotation *_lastFocused; + NAPinAnnotation *_lastFocused; } @property (nonatomic, strong) NSMutableArray *annotations; @property (nonatomic, assign) CGSize size; @@ -26,55 +27,59 @@ @implementation NAInteractiveDemoViewController - (void)viewDidLoad { [super viewDidLoad]; - + self.annotations = [[NSMutableArray alloc] init]; - + UIImage *image = [UIImage imageNamed:@"australia"]; - + self.mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f]; - + [self.mapView displayMap:image]; - + self.size = image.size; - + _count = 0; _lastFocused = nil; } - -(IBAction)addPin:(id)sender{ - + int x = (arc4random() % (int)self.size.width); int y = (arc4random() % (int)self.size.width); - + CGPoint point = CGPointMake(x, y); + [self addPinAt:point withColor:arc4random() % 3]; +} + +-(void)addPinAt:(CGPoint)point withColor:(NAPinColor)color{ + [self.mapView centreOnPoint:point animated:YES]; - - NAAnnotation *annotation = [NAAnnotation annotationWithPoint:point]; - + + NAPinAnnotation *annotation = [NAPinAnnotation annotationWithPoint:point]; + annotation.title = [NSString stringWithFormat:@"Pin %d", ++_count]; - - annotation.color = arc4random() % 3; - + + annotation.color = color; + [self.mapView addAnnotation:annotation animated:YES]; - + [self.annotations addObject:annotation]; - + _lastFocused = annotation; - + } -(IBAction)removePin:(id)sender{ - + if([self.annotations count] <= 0 || _lastFocused == nil) return; - + [self.mapView centreOnPoint:_lastFocused.point animated:YES]; - + [self.mapView removeAnnotation:_lastFocused]; [self.annotations removeObject:_lastFocused]; - + _lastFocused = ([self.annotations count] > 0) ? [self.annotations objectAtIndex:[self.annotations count]-1] : nil; } @@ -82,8 +87,12 @@ -(IBAction)selectRandom:(id)sender{ if([self.annotations count] <= 0) return; int rand = (arc4random() % (int)[self.annotations count]); - NAAnnotation *annotation = [self.annotations objectAtIndex:rand]; + [self selectPinAt:rand]; +} +-(void)selectPinAt:(NSInteger)index{ + NAPinAnnotation *annotation = [self.annotations objectAtIndex:index]; + [self.mapView selectAnnotation:annotation animated:YES]; _lastFocused = annotation; diff --git a/Demo/Demo/NAInteractiveDemoViewController.xib b/Demo/Demo/NAInteractiveDemoViewController.xib index 2135bc8..4e083d1 100644 --- a/Demo/Demo/NAInteractiveDemoViewController.xib +++ b/Demo/Demo/NAInteractiveDemoViewController.xib @@ -258,7 +258,7 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - NAMapView + NAPinAnnotationMapView com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -295,13 +295,13 @@ mapView - NAMapView + NAPinAnnotationMapView mapView mapView - NAMapView + NAPinAnnotationMapView @@ -310,7 +310,7 @@ - NAMapView + NAPinAnnotationMapView UIScrollView showCallOut: @@ -325,7 +325,7 @@ IBProjectSource - ./Classes/NAMapView.h + ./Classes/NAPinAnnotationMapView.h diff --git a/Demo/Demo/NALoadViaNIBDemoViewController.m b/Demo/Demo/NALoadViaNIBDemoViewController.m index e2941f4..16c7900 100644 --- a/Demo/Demo/NALoadViaNIBDemoViewController.m +++ b/Demo/Demo/NALoadViaNIBDemoViewController.m @@ -7,56 +7,40 @@ // #import "NALoadViaNIBDemoViewController.h" +#import "NAPinAnnotation.h" @implementation NALoadViaNIBDemoViewController @synthesize mapView = _mapView; -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil -{ - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; -} - - (void)viewDidLoad { [super viewDidLoad]; - + [self.mapView displayMap:[UIImage imageNamed:@"australia"]]; - + self.mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f]; - NAAnnotation *melbourne = [NAAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)]; - melbourne.title = @"Melbourne"; - melbourne.subtitle = @"I have a subtitle"; - melbourne.color = NAPinColorGreen; - + NAPinAnnotation *melbourne = [NAPinAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)]; + melbourne.title = @"Melbourne"; + melbourne.subtitle = @"I have a subtitle"; + melbourne.color = NAPinColorGreen; + [self.mapView addAnnotation:melbourne animated:NO]; - - NAAnnotation * perth = [NAAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)]; - perth.title = @"Perth"; - perth.subtitle = @"I have a button"; + + NAPinAnnotation *perth = [NAPinAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)]; + perth.title = @"Perth"; + perth.subtitle = @"I have a button"; perth.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; - perth.color = NAPinColorRed; - + perth.color = NAPinColorRed; + [self.mapView addAnnotation:perth animated:NO]; - - NAAnnotation * brisbane = [NAAnnotation annotationWithPoint:CGPointMake(679.0f, 302.0f)]; - brisbane.title = @"Brisbane"; - brisbane.color = NAPinColorPurple; - - [self.mapView addAnnotation:brisbane animated:NO]; - -} -- (void)viewDidUnload -{ - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; + NAPinAnnotation *brisbane = [NAPinAnnotation annotationWithPoint:CGPointMake(679.0f, 302.0f)]; + brisbane.title = @"Brisbane"; + brisbane.color = NAPinColorPurple; + + [self.mapView addAnnotation:brisbane animated:NO]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation diff --git a/Demo/Demo/NAMasterViewController.m b/Demo/Demo/NAMasterViewController.m index a3c0a06..2431234 100644 --- a/Demo/Demo/NAMasterViewController.m +++ b/Demo/Demo/NAMasterViewController.m @@ -7,6 +7,7 @@ // #import "NAMasterViewController.h" +#import "NAPlainDemoViewController.h" #import "NABasicDemoViewController.h" #import "NALoadViaNIBDemoViewController.h" #import "NAAnimatedDemoViewController.h" @@ -23,17 +24,6 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil return self; } -- (void)viewDidLoad -{ - [super viewDidLoad]; -} - -- (void)viewDidUnload -{ - [super viewDidUnload]; - // Release any retained subviews of the main view. -} - - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); @@ -47,7 +37,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ - return 4; + return 5; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath @@ -62,15 +52,18 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N switch (indexPath.row) { case 0: - cell.textLabel.text = @"Basic demo"; + cell.textLabel.text = @"Plain demo"; break; case 1: - cell.textLabel.text = @"Load via NIB demo"; + cell.textLabel.text = @"Basic demo"; break; case 2: - cell.textLabel.text = @"Animated pins demo"; + cell.textLabel.text = @"Load via NIB demo"; break; case 3: + cell.textLabel.text = @"Animated pins demo"; + break; + case 4: cell.textLabel.text = @"Interactive demo"; break; default: @@ -82,31 +75,37 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - + if(indexPath.row == 0){ - NABasicDemoViewController *vc = [[NABasicDemoViewController alloc] initWithNibName:nil bundle:nil]; + NAPlainDemoViewController *vc = [[NAPlainDemoViewController alloc] initWithNibName:nil bundle:nil]; [self.navigationController pushViewController:vc animated:YES]; return; } if(indexPath.row == 1){ - NALoadViaNIBDemoViewController *vc = [[NALoadViaNIBDemoViewController alloc] initWithNibName:@"NALoadViaNIBDemoViewController" bundle:nil]; + NABasicDemoViewController *vc = [[NABasicDemoViewController alloc] initWithNibName:nil bundle:nil]; [self.navigationController pushViewController:vc animated:YES]; return; } if(indexPath.row == 2){ - NAAnimatedDemoViewController *vc = [[NAAnimatedDemoViewController alloc] initWithNibName:nil bundle:nil]; + NALoadViaNIBDemoViewController *vc = [[NALoadViaNIBDemoViewController alloc] initWithNibName:@"NALoadViaNIBDemoViewController" bundle:nil]; [self.navigationController pushViewController:vc animated:YES]; return; } if(indexPath.row == 3){ - NAInteractiveDemoViewController *vc = [[NAInteractiveDemoViewController alloc] initWithNibName:@"NAInteractiveDemoViewController" bundle:nil]; + NAAnimatedDemoViewController *vc = [[NAAnimatedDemoViewController alloc] initWithNibName:nil bundle:nil]; [self.navigationController pushViewController:vc animated:YES]; return; } + if(indexPath.row == 4){ + NAInteractiveDemoViewController *vc = [[NAInteractiveDemoViewController alloc] initWithNibName:@"NAInteractiveDemoViewController" bundle:nil]; + [self.navigationController pushViewController:vc animated:YES]; + return; + } + } @end diff --git a/Demo/Demo/NAPlainDemoViewController.h b/Demo/Demo/NAPlainDemoViewController.h new file mode 100644 index 0000000..790f208 --- /dev/null +++ b/Demo/Demo/NAPlainDemoViewController.h @@ -0,0 +1,13 @@ +// +// NAPlainDemoViewController.h +// Demo +// +// Created by Daniel Doubrovkine on 3/7/14. +// Copyright (c) 2014 neilang.com. All rights reserved. +// + +#import + +@interface NAPlainDemoViewController : UIViewController + +@end diff --git a/Demo/Demo/NAPlainDemoViewController.m b/Demo/Demo/NAPlainDemoViewController.m new file mode 100644 index 0000000..f4f0fd0 --- /dev/null +++ b/Demo/Demo/NAPlainDemoViewController.m @@ -0,0 +1,45 @@ +// +// NAPlainDemoViewController.m +// Demo +// +// Created by Daniel Doubrovkine on 3/7/14. +// Copyright (c) 2014 neilang.com. All rights reserved. +// + +#import "NAPlainDemoViewController.h" +#import "NAMapView.h" + +@implementation NAPlainDemoViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + NAMapView *mapView = [[NAMapView alloc] initWithFrame:self.view.bounds]; + + mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f]; + mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + + mapView.minimumZoomScale = 0.5f; + mapView.maximumZoomScale = 1.5f; + + [mapView displayMap:[UIImage imageNamed:@"australia"]]; + + [self.view addSubview:mapView]; + + NAAnnotation *melbourne = [NAAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)]; + [mapView addAnnotation:melbourne animated:NO]; + + NAAnnotation *perth = [NAAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)]; + [mapView addAnnotation:perth animated:YES]; + + NAAnnotation *brisbane = [NAAnnotation annotationWithPoint:CGPointMake(679.0f, 302.0f)]; + [mapView addAnnotation:brisbane animated:NO]; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +@end diff --git a/Demo/DemoTests/DemoTests-Prefix.pch b/Demo/DemoTests/DemoTests-Prefix.pch index 15d92aa..396c2eb 100644 --- a/Demo/DemoTests/DemoTests-Prefix.pch +++ b/Demo/DemoTests/DemoTests-Prefix.pch @@ -18,5 +18,6 @@ #include #include #include + #include #endif diff --git a/Demo/DemoTests/NABasicDemoViewControllerTests.m b/Demo/DemoTests/NABasicDemoViewControllerTests.m new file mode 100644 index 0000000..9dc7e08 --- /dev/null +++ b/Demo/DemoTests/NABasicDemoViewControllerTests.m @@ -0,0 +1,27 @@ +// +// NABasicDemoViewControllerTests.m +// Demo +// +// Created by Daniel Doubrovkine on 3/7/14. +// Copyright (c) 2014 neilang.com. All rights reserved. +// + +#import "NABasicDemoViewController.h" +#import "NAPinAnnotation.h" + +SpecBegin(NABasicDemoViewController) + +setGlobalReferenceImageDir(FB_REFERENCE_IMAGE_DIR); + +__block NABasicDemoViewController *vc = nil; + +beforeEach(^{ + vc = [[NABasicDemoViewController alloc] init]; + expect(vc.view).willNot.beNil(); +}); + +it(@"displays map with a pin", ^{ + expect(vc.view).to.haveValidSnapshotNamed(@"default"); +}); + +SpecEnd diff --git a/Demo/DemoTests/NAInteractiveDemoViewControllerTests.m b/Demo/DemoTests/NAInteractiveDemoViewControllerTests.m new file mode 100644 index 0000000..7d46a3a --- /dev/null +++ b/Demo/DemoTests/NAInteractiveDemoViewControllerTests.m @@ -0,0 +1,46 @@ +// +// NAInteractiveDemoViewControllerTests.m +// Demo +// +// Created by Daniel Doubrovkine on 3/7/14. +// Copyright (c) 2014 neilang.com. All rights reserved. +// + +#import "NAInteractiveDemoViewController.h" + +SpecBegin(NAInteractiveDemoViewController) + +setGlobalReferenceImageDir(FB_REFERENCE_IMAGE_DIR); + +__block NAInteractiveDemoViewController *vc = nil; + +beforeEach(^{ + vc = [[NAInteractiveDemoViewController alloc] init]; + expect(vc.view).willNot.beNil(); +}); + +it(@"doesn't display any pins", ^{ + expect(vc.view).to.haveValidSnapshotNamed(@"default"); +}); + +it(@"adds a pin", ^{ + [vc addPinAt:CGPointMake(100, 200) withColor:NAPinColorRed]; + expect(vc.view).to.haveValidSnapshotNamed(@"add"); + +}); + +it(@"removes a pin", ^{ + [vc addPinAt:CGPointMake(100, 200) withColor:NAPinColorRed]; + [vc addPinAt:CGPointMake(200, 300) withColor:NAPinColorGreen]; + [vc removePin:nil]; + expect(vc.view).to.haveValidSnapshotNamed(@"remove"); +}); + +pending(@"selects a pin", ^{ + [vc addPinAt:CGPointMake(100, 200) withColor:NAPinColorRed]; + [vc addPinAt:CGPointMake(200, 300) withColor:NAPinColorGreen]; + [vc selectPinAt:1]; + expect(vc.view).to.haveValidSnapshotNamed(@"select"); +}); + +SpecEnd diff --git a/Demo/DemoTests/NALoadViaNIBDemoViewControllerTests.m b/Demo/DemoTests/NALoadViaNIBDemoViewControllerTests.m new file mode 100644 index 0000000..c7bb549 --- /dev/null +++ b/Demo/DemoTests/NALoadViaNIBDemoViewControllerTests.m @@ -0,0 +1,21 @@ +// +// NAInteractiveLoadViaNIBDemoViewControllerTests.m +// Demo +// +// Created by Daniel Doubrovkine on 3/7/14. +// Copyright (c) 2014 neilang.com. All rights reserved. +// + +#import "NALoadViaNIBDemoViewController.h" + +SpecBegin(NALoadViaNIBDemoViewController) + +setGlobalReferenceImageDir(FB_REFERENCE_IMAGE_DIR); + +it(@"displays a menu", ^{ + NALoadViaNIBDemoViewController *vc = [[NALoadViaNIBDemoViewController alloc] init]; + expect(vc.view).willNot.beNil(); + expect(vc.view).to.haveValidSnapshotNamed(@"default"); +}); + +SpecEnd diff --git a/Demo/DemoTests/NAMasterViewControllerTests.m b/Demo/DemoTests/NAMasterViewControllerTests.m new file mode 100644 index 0000000..1b2d8a1 --- /dev/null +++ b/Demo/DemoTests/NAMasterViewControllerTests.m @@ -0,0 +1,21 @@ +// +// DemoMenuTests.m +// Demo +// +// Created by Daniel Doubrovkine on 3/7/14. +// Copyright (c) 2014 neilang.com. All rights reserved. +// + +#import "NAMasterViewController.h" + +SpecBegin(NAMasterViewController) + +setGlobalReferenceImageDir(FB_REFERENCE_IMAGE_DIR); + +it(@"displays the master menu", ^{ + NAMasterViewController *vc = [[NAMasterViewController alloc] initWithNibName:@"NAMasterViewController" bundle:nil]; + expect(vc.view).willNot.beNil(); + expect(vc.view).to.haveValidSnapshotNamed(@"default"); +}); + +SpecEnd diff --git a/Demo/DemoTests/NAPlainDemoViewControllerTests.m b/Demo/DemoTests/NAPlainDemoViewControllerTests.m new file mode 100644 index 0000000..3f1553f --- /dev/null +++ b/Demo/DemoTests/NAPlainDemoViewControllerTests.m @@ -0,0 +1,21 @@ +// +// NAPlainDemoViewControllerTests.m +// Demo +// +// Created by Daniel Doubrovkine on 3/8/14. +// Copyright (c) 2014 neilang.com. All rights reserved. +// + +#import "NAPlainDemoViewController.h" + +SpecBegin(NAPlainDemoViewController) + +setGlobalReferenceImageDir(FB_REFERENCE_IMAGE_DIR); + +it(@"displays map with a pin", ^{ + NAPlainDemoViewController *vc = [[NAPlainDemoViewController alloc] init]; + expect(vc.view).willNot.beNil(); + expect(vc.view).to.haveValidSnapshotNamed(@"default"); +}); + +SpecEnd \ No newline at end of file diff --git a/Demo/DemoTests/ReferenceImages/NABasicDemoViewControllerSpec/default@2x.png b/Demo/DemoTests/ReferenceImages/NABasicDemoViewControllerSpec/default@2x.png new file mode 100644 index 0000000..73d70a1 Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NABasicDemoViewControllerSpec/default@2x.png differ diff --git a/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/add@2x.png b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/add@2x.png new file mode 100644 index 0000000..5b408ab Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/add@2x.png differ diff --git a/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/default@2x.png b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/default@2x.png new file mode 100644 index 0000000..3c5e95c Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/default@2x.png differ diff --git a/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/remove@2x.png b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/remove@2x.png new file mode 100644 index 0000000..d6b9fee Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/remove@2x.png differ diff --git a/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/select@2x.png b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/select@2x.png new file mode 100644 index 0000000..264c3f7 Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NAInteractiveDemoViewControllerSpec/select@2x.png differ diff --git a/Demo/DemoTests/ReferenceImages/NALoadViaNIBDemoViewControllerSpec/default@2x.png b/Demo/DemoTests/ReferenceImages/NALoadViaNIBDemoViewControllerSpec/default@2x.png new file mode 100644 index 0000000..ae5c2a2 Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NALoadViaNIBDemoViewControllerSpec/default@2x.png differ diff --git a/Demo/DemoTests/ReferenceImages/NAMasterViewControllerSpec/default@2x.png b/Demo/DemoTests/ReferenceImages/NAMasterViewControllerSpec/default@2x.png new file mode 100644 index 0000000..e85f659 Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NAMasterViewControllerSpec/default@2x.png differ diff --git a/Demo/DemoTests/ReferenceImages/NAPlainDemoViewControllerSpec/default@2x.png b/Demo/DemoTests/ReferenceImages/NAPlainDemoViewControllerSpec/default@2x.png new file mode 100644 index 0000000..67c38f9 Binary files /dev/null and b/Demo/DemoTests/ReferenceImages/NAPlainDemoViewControllerSpec/default@2x.png differ diff --git a/Demo/Podfile b/Demo/Podfile index 8cd2465..e92d357 100644 --- a/Demo/Podfile +++ b/Demo/Podfile @@ -1,7 +1,9 @@ pod "NAMapKit", :path => "../namapkit.podspec" - + target "DemoTests" do pod 'Specta', '~> 0.2.1' pod 'Expecta', '~> 0.2.3' + pod 'FBSnapshotTestCase', :git => 'https://github.com/facebook/ios-snapshot-test-case' + pod 'EXPMatchers+FBSnapshotTest', :git => 'https://github.com/dblock/ios-snapshot-test-case-expecta' end diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 8560616..a4afe6a 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -1,19 +1,30 @@ PODS: - Expecta (0.2.4) + - EXPMatchers+FBSnapshotTest (1.0): + - Expecta + - FBSnapshotTestCase (1.1) - NAMapKit (2.1) - Specta (0.2.1) DEPENDENCIES: - Expecta (~> 0.2.3) + - EXPMatchers+FBSnapshotTest (from `https://github.com/dblock/ios-snapshot-test-case-expecta`) + - FBSnapshotTestCase (from `https://github.com/facebook/ios-snapshot-test-case`) - NAMapKit (from `../namapkit.podspec`) - Specta (~> 0.2.1) EXTERNAL SOURCES: + EXPMatchers+FBSnapshotTest: + :git: https://github.com/dblock/ios-snapshot-test-case-expecta + FBSnapshotTestCase: + :git: https://github.com/facebook/ios-snapshot-test-case NAMapKit: :path: ../namapkit.podspec SPEC CHECKSUMS: Expecta: 5c147dedfea5fbcf773995f7e65020abcc936ce5 + EXPMatchers+FBSnapshotTest: bdea3de1a112fda973313b3cdeb856646e9546d6 + FBSnapshotTestCase: 188c80bfcb72e744eb0b99d45989d12687c40cf8 NAMapKit: 2cc4a881da004a182f8f296195b94919dbc997f6 Specta: 2d06220591110c6d9757d8be8ecf8e63aa40dc2a diff --git a/NAMapKit/NAAnnotation.h b/NAMapKit/NAAnnotation.h index 74052f0..160c040 100644 --- a/NAMapKit/NAAnnotation.h +++ b/NAMapKit/NAAnnotation.h @@ -8,21 +8,18 @@ #import -typedef enum { - NAPinColorRed, - NAPinColorGreen, - NAPinColorPurple -} NAPinColor; +@class NAMapView; @interface NAAnnotation : NSObject -@property (nonatomic, assign) CGPoint point; -@property (nonatomic, assign) NAPinColor color; -@property (nonatomic, copy) NSString *title; -@property (nonatomic, copy) NSString *subtitle; -@property (nonatomic, strong) UIButton *rightCalloutAccessoryView; +@property (nonatomic, assign) CGPoint point; +@property (nonatomic, readonly) UIView *view; -+ (id)annotationWithPoint:(CGPoint)point; -- (id)initWithPoint:(CGPoint)point; ++(id)annotationWithPoint:(CGPoint)point; +-(id)initWithPoint:(CGPoint)point; +-(void)addToMapView:(NAMapView *)mapView animated:(BOOL)animate; +-(void)removeFromMapView; +-(void)updatePosition; +-(UIView *)createViewOnMapView:(NAMapView *)mapView; @end diff --git a/NAMapKit/NAAnnotation.m b/NAMapKit/NAAnnotation.m index 0247a41..bef300f 100644 --- a/NAMapKit/NAAnnotation.m +++ b/NAMapKit/NAAnnotation.m @@ -7,14 +7,20 @@ // #import "NAAnnotation.h" +#import "NAMapView.h" + +#define NA_DOT_WIDTH 10.0f +#define NA_DOT_HEIGHT 10.0f + +@interface NAAnnotation () +@property (nonatomic, readonly) NAMapView *mapView; +@end @implementation NAAnnotation -@synthesize point = _point; -@synthesize color = _color; -@synthesize title = _title; -@synthesize subtitle = _subtitle; -@synthesize rightCalloutAccessoryView = _rightCalloutAccessoryView; +@synthesize view = _view; +@synthesize mapView = _mapView; +@synthesize point = _point; + (id)annotationWithPoint:(CGPoint)point{ return [[[self class] alloc] initWithPoint:point]; @@ -23,14 +29,58 @@ + (id)annotationWithPoint:(CGPoint)point{ - (id)initWithPoint:(CGPoint)point{ self = [super init]; if (self) { - self.point = point; - self.color = NAPinColorRed; - self.title = nil; - self.subtitle = nil; - self.rightCalloutAccessoryView = nil; + _point = point; + _mapView = nil; + _view = nil; } return self; } +-(void)addToMapView:(NAMapView *)mapView animated:(BOOL)animate +{ + NSAssert(!self.mapView, @"Annotation already added to map."); + + if (!self.view) { + _view = [self createViewOnMapView:mapView]; + } + + [mapView addSubview:self.view]; + [mapView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; + _mapView = mapView; + + [self updatePosition]; +} + +-(void)removeFromMapView +{ + [self.view removeFromSuperview]; + [self.mapView removeObserver:self forKeyPath:@"contentSize"]; + _mapView = nil; + _view = nil; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if ([keyPath isEqualToString:@"contentSize"]) { + [self updatePosition]; + } +} + +-(void)updatePosition{ + CGPoint point = [self.mapView zoomRelativePoint:self.point]; + self.view.frame = (CGRect){ + .origin = point, + .size = self.view.frame.size + }; +} + +-(UIView *)createViewOnMapView:(NAMapView *)mapView +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,20,20)]; + view.alpha = 0.5; + view.layer.cornerRadius = 10; + view.backgroundColor = [UIColor redColor]; + [self updatePosition]; + return view; +} @end diff --git a/NAMapKit/NAMapView.h b/NAMapKit/NAMapView.h index 1b74b31..596cc1b 100644 --- a/NAMapKit/NAMapView.h +++ b/NAMapKit/NAMapView.h @@ -11,13 +11,14 @@ @interface NAMapView : UIScrollView -- (void)displayMap:(UIImage *)map; -- (void)addAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate; -- (void)addAnnotations:(NSArray *)annotations animated:(BOOL)animate; -- (void)centreOnPoint:(CGPoint)point animated:(BOOL)animate; -- (void)removeAnnotation:(NAAnnotation *)annotation; -- (CGPoint)zoomRelativePoint:(CGPoint)point; -- (void)selectAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate; +-(void)displayMap:(UIImage *)map; +-(void)addAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate; +-(void)addAnnotations:(NSArray *)annotations animated:(BOOL)animate; +-(void)centreOnPoint:(CGPoint)point animated:(BOOL)animate; +-(void)removeAnnotation:(NAAnnotation *)annotation; +-(CGPoint)zoomRelativePoint:(CGPoint)point; +-(void)selectAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate; +-(void)setupMap; @end diff --git a/NAMapKit/NAMapView.m b/NAMapKit/NAMapView.m index 0d935a9..ec43811 100644 --- a/NAMapKit/NAMapView.m +++ b/NAMapKit/NAMapView.m @@ -7,68 +7,48 @@ // #import "NAMapView.h" -#import "NAPinAnnotationView.h" -#import "NACallOutView.h" - -#define NA_PIN_ANIMATION_DURATION 0.5f -#define NA_CALLOUT_ANIMATION_DURATION 0.1f -#define NA_ZOOM_STEP 1.5f +#define NA_ZOOM_STEP 1.5f @interface NAMapView() -@property (nonatomic, strong) UIImageView *imageView; -@property (nonatomic, strong) NACallOutView *calloutView; -@property (nonatomic, strong) NSMutableArray *annotationViews; -@property (nonatomic, assign) CGSize orignalSize; +@property (nonatomic, strong) UIImageView *imageView; +@property (nonatomic, assign) CGSize originalSize; --(void)addAnimatedAnnontation:(NAAnnotation *)annontation; --(IBAction)showCallOut:(id)sender; -- (void)_showCallOutForAnnontationView:(NAPinAnnotationView *)annontationView animated:(BOOL)animated; --(void)hideCallOut; -(void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer; -(void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer; --(void)viewSetup; --(NAPinAnnotationView *)viewForAnnotation:(NAAnnotation *)annotation; @end @implementation NAMapView -@synthesize imageView = _imageView; -@synthesize orignalSize = _orignalSize; -@synthesize calloutView = _calloutView; -@synthesize annotationViews = _annotationViews; +@synthesize imageView = _imageView; +@synthesize originalSize = _originalSize; --(void)viewSetup{ +-(void)setupMap { self.delegate = self; - + UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)]; UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)]; - + [doubleTap setNumberOfTapsRequired:2]; [twoFingerTap setNumberOfTouchesRequired:2]; - + [self addGestureRecognizer:doubleTap]; [self addGestureRecognizer:twoFingerTap]; - - self.imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; - [self addSubview:self.imageView]; - - self.calloutView = [[NACallOutView alloc] initOnMapView:self]; - [self addObserver:self.calloutView forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; - [self addSubview:self.calloutView]; + _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; + [self addSubview:self.imageView]; } - (void)awakeFromNib { [super awakeFromNib]; - [self viewSetup]; + [self setupMap]; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - [self viewSetup]; + [self setupMap]; } return self; } @@ -77,99 +57,22 @@ - (void)displayMap:(UIImage *)map{ self.imageView.frame = CGRectMake(0.0f, 0.0f, map.size.width, map.size.height); self.imageView.image = map; CGRect imageFrame = self.imageView.frame; - self.orignalSize = CGSizeMake(CGRectGetWidth(imageFrame), CGRectGetHeight(imageFrame)); - self.contentSize = self.orignalSize; -} - --(void)addAnimatedAnnontation:(NAAnnotation *)annontation { - [self addAnnotation:annontation animated:YES]; + self.originalSize = CGSizeMake(CGRectGetWidth(imageFrame), CGRectGetHeight(imageFrame)); + self.contentSize = self.originalSize; } - (void)addAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate { - - NAPinAnnotationView *annontationView = [[NAPinAnnotationView alloc] initWithAnnotation:annotation onMapView:self]; - - [annontationView addTarget:self action:@selector(showCallOut:) forControlEvents:UIControlEventTouchDown]; - [self addObserver:annontationView forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; - - if(animate){ - annontationView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0.0f, -annontationView.center.y); - } - - [self addSubview:annontationView]; - - if(animate){ - annontationView.animating = YES; - [UIView animateWithDuration:NA_PIN_ANIMATION_DURATION animations:^{ - annontationView.transform = CGAffineTransformIdentity; - } - completion:^ (BOOL finished) { - annontationView.animating = NO; - }]; - } - - if(!self.annotationViews){ - self.annotationViews = [[NSMutableArray alloc] init]; - } - - [self.annotationViews addObject:annontationView]; - [self bringSubviewToFront:self.calloutView]; + [annotation addToMapView:self animated:animate]; } - (void)addAnnotations:(NSArray *)annotations animated:(BOOL)animate { - int i = 0; for (NAAnnotation *annotation in annotations) { - if(animate){ - [self performSelector:@selector(addAnimatedAnnontation:) withObject:annotation afterDelay:(NA_PIN_ANIMATION_DURATION * (i++ / 2.0f))]; - } - else{ - [self addAnnotation:annotation animated:NO]; - } - + [self addAnnotation:annotation animated:animate]; } } --(void)removeAnnotation:(NAAnnotation *)annotation{ - [self hideCallOut]; - for(NAPinAnnotationView *annotationView in self.annotationViews){ - if (annotationView.annotation == annotation) { - [annotationView removeFromSuperview]; - [self removeObserver:annotationView forKeyPath:@"contentSize"]; - [self.annotationViews removeObject:annotationView]; - break; - } - } -} - -- (IBAction)showCallOut:(id)sender { - if(![sender isKindOfClass:[NAPinAnnotationView class]]) return; - NAPinAnnotationView *annontationView = (NAPinAnnotationView *)sender; - [self _showCallOutForAnnontationView:annontationView animated:YES]; -} - -- (void)_showCallOutForAnnontationView:(NAPinAnnotationView *)annontationView animated:(BOOL)animated { - - if (annontationView == nil) { return; } - - NAAnnotation *annotation = annontationView.annotation; - - if(!annotation || !annotation.title) return; - - [self hideCallOut]; - - [self.calloutView setAnnotation:annotation]; - - [self centreOnPoint:annotation.point animated:animated]; - - CGFloat animationDuration = animated ? NA_CALLOUT_ANIMATION_DURATION : 0.0f; - - self.calloutView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4f, 0.4f); - self.calloutView.hidden = NO; - - [UIView animateWithDuration:animationDuration animations:^{ - self.calloutView.transform = CGAffineTransformIdentity; - }]; - +-(void)removeAnnotation:(NAAnnotation *)annotation { + [annotation removeFromMapView]; } - (void)centreOnPoint:(CGPoint)point animated:(BOOL)animate { @@ -178,47 +81,14 @@ - (void)centreOnPoint:(CGPoint)point animated:(BOOL)animate { [self setContentOffset:CGPointMake(round(x), round(y)) animated:animate]; } -- (void)selectAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate { - [self hideCallOut]; - NAPinAnnotationView *selectedView = [self viewForAnnotation:annotation]; - [self _showCallOutForAnnontationView:selectedView animated:animate]; -} - -- (NAPinAnnotationView *)viewForAnnotation: (NAAnnotation *)annotation { - for (NAPinAnnotationView *annotationView in self.annotationViews) { - if (annotationView.annotation == annotation) { - return annotationView; - } - } - return nil; -} - -- (void)hideCallOut { - self.calloutView.hidden = YES; -} - -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - if (!self.dragging) { - [self hideCallOut]; - } - - [super touchesEnded:touches withEvent:event]; -} - -(CGPoint)zoomRelativePoint:(CGPoint)point{ - float x = (self.contentSize.width / self.orignalSize.width) * point.x; - float y = (self.contentSize.height / self.orignalSize.height) * point.y; + float x = (self.contentSize.width / self.originalSize.width) * point.x; + float y = (self.contentSize.height / self.originalSize.height) * point.y; return CGPointMake(round(x), round(y)); } -- (void)dealloc { - for(NAPinAnnotationView *annotationView in self.annotationViews){ - [self removeObserver:annotationView forKeyPath:@"contentSize"]; - } - - if(self.calloutView){ - [self removeObserver:self.calloutView forKeyPath:@"contentSize"]; - } +- (void)selectAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate +{ } #pragma mark - UIScrollViewDelegate @@ -243,6 +113,4 @@ - (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer { @end -#undef NA_PIN_ANIMATION_DURATION -#undef NA_CALLOUT_ANIMATION_DURATION -#undef NA_ZOOM_STEP \ No newline at end of file +#undef NA_ZOOM_STEP diff --git a/NAMapKit/NAPinAnnotation.h b/NAMapKit/NAPinAnnotation.h new file mode 100644 index 0000000..98b1469 --- /dev/null +++ b/NAMapKit/NAPinAnnotation.h @@ -0,0 +1,26 @@ +// +// NAAnnotation.h +// NAMapKit +// +// Created by Neil Ang on 21/07/10. +// Copyright 2010 neilang.com. All rights reserved. +// + +#import "NAAnnotation.h" + +typedef enum { + NAPinColorRed, + NAPinColorGreen, + NAPinColorPurple +} NAPinColor; + +@interface NAPinAnnotation : NAAnnotation + +@property (nonatomic, assign) NAPinColor color; +@property (nonatomic, copy) NSString *title; +@property (nonatomic, copy) NSString *subtitle; +@property (nonatomic, strong) UIButton *rightCalloutAccessoryView; + +- (id)initWithPoint:(CGPoint)point; + +@end diff --git a/NAMapKit/NAPinAnnotation.m b/NAMapKit/NAPinAnnotation.m new file mode 100644 index 0000000..e1994e3 --- /dev/null +++ b/NAMapKit/NAPinAnnotation.m @@ -0,0 +1,68 @@ +// +// NAAnnotation.h +// NAMapKit +// +// Created by Neil Ang on 21/07/10. +// Copyright 2010 neilang.com. All rights reserved. +// + +#import "NAPinAnnotation.h" +#import "NAPinAnnotationView.h" + +#define NA_PIN_ANIMATION_DURATION 0.5f +#define NA_CALLOUT_ANIMATION_DURATION 0.1f + +@implementation NAPinAnnotation + +@synthesize color = _color; +@synthesize title = _title; +@synthesize subtitle = _subtitle; +@synthesize rightCalloutAccessoryView = _rightCalloutAccessoryView; + +-(id)initWithPoint:(CGPoint)point{ + self = [super initWithPoint:point]; + if (self) { + self.color = NAPinColorRed; + self.title = nil; + self.subtitle = nil; + self.rightCalloutAccessoryView = nil; + } + return self; +} + +-(UIView *)createViewOnMapView:(NAMapView *)mapView +{ + return [[NAPinAnnotationView alloc] initWithAnnotation:self onMapView:mapView]; +} + +-(void)addToMapView:(NAMapView *)mapView animated:(BOOL)animate +{ + [super addToMapView:mapView animated:animate]; + + NAPinAnnotationView *annotationView = (NAPinAnnotationView *) self.view; + + if(animate){ + annotationView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0.0f, -annotationView.center.y); + } + + [mapView addSubview:annotationView]; + + if(animate){ + annotationView.animating = YES; + [UIView animateWithDuration:NA_PIN_ANIMATION_DURATION animations:^{ + annotationView.transform = CGAffineTransformIdentity; + } completion:^ (BOOL finished) { + annotationView.animating = NO; + }]; + } +} + +-(void)updatePosition +{ + NAPinAnnotationView *annontationView = (NAPinAnnotationView *)self.view; + [annontationView updatePosition]; +} + +@end + +#undef NA_PIN_ANIMATION_DURATION \ No newline at end of file diff --git a/NAMapKit/NACallOutView.h b/NAMapKit/NAPinAnnotationCallOutView.h similarity index 63% rename from NAMapKit/NACallOutView.h rename to NAMapKit/NAPinAnnotationCallOutView.h index c9f7c6a..1bdf7e4 100644 --- a/NAMapKit/NACallOutView.h +++ b/NAMapKit/NAPinAnnotationCallOutView.h @@ -7,12 +7,12 @@ // #import -#import "NAAnnotation.h" +#import "NAPinAnnotation.h" #import "NAMapView.h" -@interface NACallOutView : UIView +@interface NAPinAnnotationCallOutView : UIView - (id)initOnMapView:(NAMapView *)mapView; -- (void)setAnnotation:(NAAnnotation *)annotation; +- (void)setAnnotation:(NAPinAnnotation *)annotation; @end diff --git a/NAMapKit/NACallOutView.m b/NAMapKit/NAPinAnnotationCallOutView.m similarity index 85% rename from NAMapKit/NACallOutView.m rename to NAMapKit/NAPinAnnotationCallOutView.m index 47ad2fa..fab7157 100644 --- a/NAMapKit/NACallOutView.m +++ b/NAMapKit/NAPinAnnotationCallOutView.m @@ -6,7 +6,7 @@ // Copyright 2010 neilang.com. All rights reserved. // -#import "NACallOutView.h" +#import "NAPinAnnotationCallOutView.h" #define NA_TITLE_STANDALONE_LABEL_HEIGHT 22.0f #define NA_TITLE_STANDALONE_FONT_SIZE 18.0f @@ -26,7 +26,7 @@ #define NA_CALLOUT_IMAGE_BG @"callout_bg.png" -@interface NACallOutView() +@interface NAPinAnnotationCallOutView() @property (nonatomic, strong) UIImageView *calloutLeftCapView; @property (nonatomic, strong) UIImageView *calloutRightCapView; @@ -45,7 +45,7 @@ -(void)positionView:(UIView *)view posX:(float)x width:(float)width; @end -@implementation NACallOutView +@implementation NAPinAnnotationCallOutView @synthesize calloutLeftCapView = _calloutLeftCapView; @synthesize calloutRightCapView = _calloutRightCapView; @@ -80,7 +80,7 @@ - (id)initOnMapView:(NAMapView *)mapView { return self; } -- (void)setAnnotation:(NAAnnotation *)annotation{ +- (void)setAnnotation:(NAPinAnnotation *)annotation{ // --- RESET --- @@ -105,16 +105,17 @@ - (void)setAnnotation:(NAAnnotation *)annotation{ float middleWidth = anchorWidth; if (annotation.subtitle) { - CGSize subtitleSize = [annotation.subtitle sizeWithFont:[UIFont boldSystemFontOfSize:NA_SUBTITLE_FONT_SIZE] constrainedToSize:CGSizeMake(maxWidth, NA_SUBTITLE_LABEL_HEIGHT) lineBreakMode:UILineBreakModeTailTruncation]; + + CGSize subtitleSize = [self text:annotation.subtitle sizeWithFont:[UIFont boldSystemFontOfSize:NA_SUBTITLE_FONT_SIZE] constrainedToSize:CGSizeMake(maxWidth, NA_SUBTITLE_LABEL_HEIGHT)]; middleWidth = MAX(subtitleSize.width, middleWidth); - CGSize titleSize = [annotation.title sizeWithFont:[UIFont boldSystemFontOfSize:NA_TITLE_FONT_SIZE] constrainedToSize:CGSizeMake(maxWidth, NA_TITLE_LABEL_HEIGHT) lineBreakMode:UILineBreakModeTailTruncation]; + CGSize titleSize = [self text:annotation.title sizeWithFont:[UIFont boldSystemFontOfSize:NA_TITLE_FONT_SIZE] constrainedToSize:CGSizeMake(maxWidth, NA_TITLE_LABEL_HEIGHT)]; middleWidth = MAX(titleSize.width, middleWidth); } else{ - CGSize titleSize = [annotation.title sizeWithFont:[UIFont boldSystemFontOfSize:NA_TITLE_STANDALONE_FONT_SIZE] constrainedToSize:CGSizeMake(maxWidth, NA_TITLE_STANDALONE_LABEL_HEIGHT) lineBreakMode:UILineBreakModeTailTruncation]; + CGSize titleSize = [self text:annotation.title sizeWithFont:[UIFont boldSystemFontOfSize:NA_TITLE_STANDALONE_FONT_SIZE] constrainedToSize:CGSizeMake(maxWidth, NA_TITLE_STANDALONE_LABEL_HEIGHT)]; middleWidth = MAX(titleSize.width, middleWidth); } @@ -224,6 +225,21 @@ -(void)positionView:(UIView *)view posX:(float)x{ [self positionView:view posX:x width:view.frame.size.width]; } +-(CGSize)text:(NSString*)text sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size{ + // TODO: this used to include lineBreakMode:NSLineBreakByTruncatingTail, do we need to do something about it? + + NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: + font, NSFontAttributeName, + nil]; + + CGRect frame = [text boundingRectWithSize:size + options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) + attributes:attributesDictionary + context:nil]; + + return frame.size; +} + @end #undef NA_TITLE_STANDALONE_LABEL_HEIGHT diff --git a/NAMapKit/NAPinAnnotationMapView.h b/NAMapKit/NAPinAnnotationMapView.h new file mode 100644 index 0000000..b8b606b --- /dev/null +++ b/NAMapKit/NAPinAnnotationMapView.h @@ -0,0 +1,15 @@ +// +// NAPinAnnotationMapView.h +// +// Created by Daniel Doubrovkine on 3/7/14. +// +// + +#import "NAMapView.h" +#import "NAPinAnnotation.h" +#import "NAPinAnnotationView.h" +#import "NAPinAnnotationCallOutView.h" + +@interface NAPinAnnotationMapView : NAMapView + +@end diff --git a/NAMapKit/NAPinAnnotationMapView.m b/NAMapKit/NAPinAnnotationMapView.m new file mode 100644 index 0000000..9bc5bbf --- /dev/null +++ b/NAMapKit/NAPinAnnotationMapView.m @@ -0,0 +1,96 @@ +// +// NAPinAnnotationMapView.m +// +// Created by Daniel Doubrovkine on 3/7/14. +// + +#import "NAPinAnnotationMapView.h" + +#define NA_CALLOUT_ANIMATION_DURATION 0.1f + +@interface NAPinAnnotationMapView() + +@property (nonatomic, strong) NAPinAnnotationCallOutView *calloutView; + +-(IBAction)showCallOut:(id)sender; +-(void)hideCallOut; + +@end + +@implementation NAPinAnnotationMapView + +-(void)setupMap +{ + [super setupMap]; + + self.calloutView = [[NAPinAnnotationCallOutView alloc] initOnMapView:self]; + [self addObserver:self.calloutView forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil]; + [self addSubview:self.calloutView]; +} + +-(void)addAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate { + [super addAnnotation:annotation animated:animate]; + if ([annotation.view isKindOfClass:NAPinAnnotationView.class]) { + NAPinAnnotationView *annotationView = (NAPinAnnotationView *) annotation.view; + [annotationView addTarget:self action:@selector(showCallOut:) forControlEvents:UIControlEventTouchDown]; + } + [self bringSubviewToFront:self.calloutView]; +} + +- (void)selectAnnotation:(NAAnnotation *)annotation animated:(BOOL)animate { + [self hideCallOut]; + if([annotation isKindOfClass:NAPinAnnotation.class]) { + [self showCalloutForAnnotation:(NAPinAnnotation *)annotation animated:animate]; + } +} + +-(void)removeAnnotation:(NAAnnotation *)annotation{ + [self hideCallOut]; + [super removeAnnotation:annotation]; +} + +-(IBAction)showCallOut:(id)sender { + if([sender isKindOfClass:[NAPinAnnotationView class]]) { + NAPinAnnotationView *annontationView = (NAPinAnnotationView *)sender; + [self showCalloutForAnnotation:annontationView.annotation animated:YES]; + } +} + +-(void)showCalloutForAnnotation:(NAPinAnnotation *)annotation animated:(BOOL)animated { + [self hideCallOut]; + + [self.calloutView setAnnotation:annotation]; + + [self centreOnPoint:annotation.point animated:animated]; + + CGFloat animationDuration = animated ? NA_CALLOUT_ANIMATION_DURATION : 0.0f; + + self.calloutView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.4f, 0.4f); + self.calloutView.hidden = NO; + + [UIView animateWithDuration:animationDuration animations:^{ + self.calloutView.transform = CGAffineTransformIdentity; + }]; +} + +- (void)hideCallOut { + self.calloutView.hidden = YES; +} + +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { + if (!self.dragging) { + [self hideCallOut]; + } + + [super touchesEnded:touches withEvent:event]; +} + +- (void)dealloc { + if(self.calloutView) { + [self removeObserver:self.calloutView forKeyPath:@"contentSize"]; + } +} + +@end + +#undef NA_CALLOUT_ANIMATION_DURATION diff --git a/NAMapKit/NAPinAnnotationView.h b/NAMapKit/NAPinAnnotationView.h index 118afdb..28fe3b8 100644 --- a/NAMapKit/NAPinAnnotationView.h +++ b/NAMapKit/NAPinAnnotationView.h @@ -7,14 +7,15 @@ // #import -#import "NAAnnotation.h" +#import "NAPinAnnotation.h" #import "NAMapView.h" @interface NAPinAnnotationView : UIButton -- (id)initWithAnnotation:(NAAnnotation *)annotation onMapView:(NAMapView *)mapView; +@property (nonatomic, retain) NAPinAnnotation *annotation; +@property (nonatomic, assign) BOOL animating; -@property (nonatomic, retain) NAAnnotation *annotation; -@property (nonatomic, assign) BOOL animating; +-(id)initWithAnnotation:(NAPinAnnotation *)annotation onMapView:(NAMapView *)mapView; +-(void)updatePosition; @end diff --git a/NAMapKit/NAPinAnnotationView.m b/NAMapKit/NAPinAnnotationView.m index 97334f0..a9719ab 100644 --- a/NAMapKit/NAPinAnnotationView.m +++ b/NAMapKit/NAPinAnnotationView.m @@ -14,11 +14,7 @@ #define NA_PIN_POINT_Y 35.0f @interface NAPinAnnotationView() - -- (void)updatePosition; - @property (nonatomic, weak) NAMapView *mapView; - @end @implementation NAPinAnnotationView @@ -27,21 +23,19 @@ @implementation NAPinAnnotationView @synthesize animating = _animating; @synthesize mapView = _mapView; -- (id)initWithAnnotation:(NAAnnotation *)annotation onMapView:(NAMapView *)mapView { +- (id)initWithAnnotation:(NAPinAnnotation *)annotation onMapView:(NAMapView *)mapView { self = [super initWithFrame:CGRectZero]; if (self) { self.mapView = mapView; self.annotation = annotation; self.animating = NO; - - [self updatePosition]; } return self; } - (void)setAnimating:(BOOL)animating{ _animating = animating; - + NSString *pinImage; switch (self.annotation.color) { case NAPinColorGreen: @@ -54,9 +48,9 @@ - (void)setAnimating:(BOOL)animating{ pinImage = @"pinRed"; break; } - + NSString * image = _animating ? [NSString stringWithFormat:@"%@Floating", pinImage] : pinImage; - + [self setImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; } @@ -67,12 +61,6 @@ -(void)updatePosition{ self.frame = CGRectMake(point.x, point.y, NA_PIN_WIDTH, NA_PIN_HEIGHT); } -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if ([keyPath isEqualToString:@"contentSize"]) { - [self updatePosition]; - } -} - @end #undef NA_PIN_WIDTH diff --git a/README.md b/README.md new file mode 100644 index 0000000..9be5a9d --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +NAMapKit +======== + +[![Build Status](https://travis-ci.org/neilang/NAMapKit.png)](https://travis-ci.org/neilang/NAMapKit) + +Lets you drop MapKit style pins onto a standard UIImage. Also includes callouts, multi-colored pins, animation, zoom and gestures. + +![Screenshot 1](screenshot1.png) +![Screenshot 2](screenshot2.png) + +Usage +----- + +#### Default Annotations + +Create a map in a view controller. + +``` objc +NAMapView *mapView = [[NAMapView alloc] initWithFrame:self.view.bounds]; + +mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f]; +mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + +mapView.minimumZoomScale = 0.5f; +mapView.maximumZoomScale = 1.5f; + +[mapView displayMap:[UIImage imageNamed:@"australia"]]; + +[self.view addSubview:mapView]; +``` + +Add annotations. + +``` +NAAnnotation *dot = [NAAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)]; +[mapView addAnnotation:dot animated:NO]; +``` + +#### Custom Annotations + +The default implementation places a red semi-transparent dot on the map. Subclass [NAAnnotation](NAMapKit/NAAnnotation.h) and implement `createViewOnMapView` that returns a custom annotation view. Optionally implement `addToMapView` when the annotation is added, and `updatePosition` to change the location of the view every time the map is zoomed in or zoomed out. + +You can find a complete example in [NAPinAnnotation.h](NAMapKit/NAPinAnnotation.h)/[.m](NAMapKit/NAPinAnnotation.m). + +Notes +----- + +Current version _requires ARC and iOS5_ (untested on iOS4). If you are developing for iOS3/4, checkout the version 1.0 tag of the repository. + +If you are using Interface Builder, you can add a UIScrollView to your XIB and change the class to "NAMapView" to use the framework. + +Attribution +----------- + +When using this code please include the following attribution: + +**Includes NAMapKit code developed by [Neil Ang](http://neilang.com/) and [Tony Arnold](http://thecocoabots.com/).** + +Have an app on the AppStore that's using NAMapKit? [Add it to the wiki](https://github.com/neilang/NAMapKit/wiki). diff --git a/ReadMe.md b/ReadMe.md deleted file mode 100644 index c9e57ef..0000000 --- a/ReadMe.md +++ /dev/null @@ -1,29 +0,0 @@ -NAMapKit -======== - -[![Build Status](https://travis-ci.org/neilang/NAMapKit.png)](https://travis-ci.org/neilang/NAMapKit) - -Lets you drop MapKit style pins onto a standard UIImage - _also includes callouts, multi-colored pins, animation, zoom and gestures_. - - -![Screenshot 1](screenshot1.png) -![Screenshot 2](screenshot2.png) - -Usage ------- - -Current version _requires ARC and iOS5_ (untested on iOS4). If you are developing for iOS3/4, checkout the version 1.0 tag of the repository. - -Example code on how to use this framework can be found in the demo app. - -If you are using Interface Builder, you can add a UIScrollView to your XIB and change the class to "NAMapView" to use the framework. - - -Attribution ------------ - -When using this code please include the following attribution: - -**Includes NAMapKit code developed by [Neil Ang](http://neilang.com/) and [Tony Arnold](http://thecocoabots.com/).** - -Have an app on the AppStore that's using NAMapKit? [Add it to the wiki](https://github.com/neilang/NAMapKit/wiki).