Permalink
Browse files

Laying the groundwork.

- Entire control in a single .h/.m file pair
- Exact UICalloutView background images embedded via base64 technique
- Sample layout matches UICalloutView exactly
- Text matches exactly
- Sample project allows easy comparison of SMCalloutView to UICalloutView
  • Loading branch information...
1 parent 7bfd565 commit b3d169e5fc442f9837e2421a5420dd31b6bb3404 @nfarina committed Aug 8, 2012
View
@@ -0,0 +1 @@
+xcuserdata
@@ -1,15 +0,0 @@
-//
-// AppDelegate.h
-// CalloutViewSamples
-//
-// Created by Nick Farina on 8/8/12.
-//
-//
-
-#import <UIKit/UIKit.h>
-
-@interface AppDelegate : UIResponder <UIApplicationDelegate>
-
-@property (strong, nonatomic) UIWindow *window;
-
-@end
@@ -1,49 +0,0 @@
-//
-// AppDelegate.m
-// CalloutViewSamples
-//
-// Created by Nick Farina on 8/8/12.
-//
-//
-
-#import "AppDelegate.h"
-
-@implementation AppDelegate
-
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
-{
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- self.window.backgroundColor = [UIColor whiteColor];
- [self.window makeKeyAndVisible];
- return YES;
-}
-
-- (void)applicationWillResignActive:(UIApplication *)application
-{
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
-}
-
-- (void)applicationDidEnterBackground:(UIApplication *)application
-{
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
-}
-
-- (void)applicationWillEnterForeground:(UIApplication *)application
-{
- // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
-}
-
-- (void)applicationDidBecomeActive:(UIApplication *)application
-{
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
-}
-
-- (void)applicationWillTerminate:(UIApplication *)application
-{
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
-}
-
-@end
@@ -1,2 +0,0 @@
-/* Localized versions of Info.plist keys */
-
View
@@ -0,0 +1,18 @@
+#import <UIKit/UIKit.h>
+
+enum {
+ SMCalloutArrowDirectionUp = 1UL << 0,
+ SMCalloutArrowDirectionDown = 1UL << 1,
+ SMCalloutArrowDirectionAny = SMCalloutArrowDirectionUp | SMCalloutArrowDirectionDown
+};
+typedef NSUInteger SMCalloutArrowDirection;
+
+@interface SMCalloutView : UIView
+
+@property (nonatomic, copy) NSString *title;
+
+- (void)presentCalloutFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(SMCalloutArrowDirection)arrowDirections animated:(BOOL)animated;
+- (void)presentCalloutFromView:(UIView *)view permittedArrowDirections:(SMCalloutArrowDirection)arrowDirections animated:(BOOL)animated;
+- (void)dismissCalloutAnimated:(BOOL)animated;
+
+@end
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,7 @@
+#import <MapKit/MapKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate, MKMapViewDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@end
View
@@ -0,0 +1,112 @@
+#import "AppDelegate.h"
+#import "SMCalloutView.h"
+
+@interface MapAnnotation : NSObject <MKAnnotation>
+@property (nonatomic, copy) NSString *title;
+@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
+@end
+@implementation MapAnnotation
+@end
+
+@interface NSObject (RecursiveDescription)
+- (NSString *)recursiveDescription;
+@end
+
+@implementation AppDelegate {
+// UIScrollView *scrollView;
+// UIImageView *marsView;
+ MKMapView *topMapView, *bottomMapView;
+ MKPinAnnotationView *topPin, *bottomPin;
+ SMCalloutView *calloutView;
+}
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ self.window.backgroundColor = [UIColor whiteColor];
+
+ CGRect half = CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height/2);
+
+ MapAnnotation *capeCanaveral = [MapAnnotation new];
+ capeCanaveral.coordinate = (CLLocationCoordinate2D){28.388154, -80.604200};
+ capeCanaveral.title = @"Cape Canaveral";
+
+ //
+ // Fill top half with a custom view (image) inside a scroll view along with a custom pin view that triggers our custom MTCalloutView.
+ //
+
+// scrollView = [[UIScrollView alloc] initWithFrame:half];
+//
+// marsView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mars.jpg"]];
+// marsView.userInteractionEnabled = YES;
+// [marsView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(marsTapped)]];
+//
+// [scrollView addSubview:marsView];
+// scrollView.contentSize = marsView.frame.size;
+//
+// pin = [[MKPinAnnotationView alloc] initWithAnnotation:nil reuseIdentifier:@""];
+// pin.center = CGPointMake(half.size.width/2, half.size.height/2 + 50);
+// [pin addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pinTapped)]];
+// [marsView addSubview:pin];
+
+ //
+ // Fill top half with an MKMapView with a pin view that triggers our custom MTCalloutView.
+ //
+
+ topPin = [[MKPinAnnotationView alloc] initWithAnnotation:capeCanaveral reuseIdentifier:@""];
+ topPin.canShowCallout = NO;
+ [topPin addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pinTapped:)]];
+
+ topMapView = [[MKMapView alloc] initWithFrame:half];
+ topMapView.delegate = self;
+ [topMapView addAnnotation:capeCanaveral];
+
+ calloutView = [SMCalloutView new];
+ calloutView.title = capeCanaveral.title;
+
+ //
+ // Fill the bottom half of our window with a standard MKMapView with pin+callout for comparison
+ //
+
+ bottomPin = [[MKPinAnnotationView alloc] initWithAnnotation:capeCanaveral reuseIdentifier:@""];
+
+ bottomMapView = [[MKMapView alloc] initWithFrame:CGRectOffset(half, 0, half.size.height)];
+ [bottomMapView addAnnotation:capeCanaveral];
+
+ //
+ // Put it all on the screen.
+ //
+
+ [self.window addSubview:topMapView];
+ [self.window addSubview:bottomMapView];
+
+ [self.window makeKeyAndVisible];
+
+ [self performSelector:@selector(popup) withObject:nil afterDelay:2];
+ [self performSelector:@selector(printHierarchy) withObject:nil afterDelay:5];
+
+ return YES;
+}
+
+- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
+ return topPin;
+}
+
+- (void)pinTapped:(UITapGestureRecognizer *)recognizer {
+ [calloutView presentCalloutFromView:recognizer.view permittedArrowDirections:SMCalloutArrowDirectionDown animated:YES];
+}
+
+- (void)marsTapped {
+ [calloutView dismissCalloutAnimated:YES];
+}
+
+- (void)popup {
+ [calloutView presentCalloutFromView:topPin permittedArrowDirections:SMCalloutArrowDirectionDown animated:YES];
+ [bottomMapView selectAnnotation:bottomPin.annotation animated:YES];
+}
+
+- (void)printHierarchy {
+ NSLog(@"%@", self.window.recursiveDescription);
+}
+
+@end
@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
+ <key>UIStatusBarStyle</key>
+ <string>UIStatusBarStyleBlackOpaque</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
@@ -10,29 +10,35 @@
011CA08E15D3144E007DBC54 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 011CA08D15D3144E007DBC54 /* UIKit.framework */; };
011CA09015D3144E007DBC54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 011CA08F15D3144E007DBC54 /* Foundation.framework */; };
011CA09215D3144E007DBC54 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 011CA09115D3144E007DBC54 /* CoreGraphics.framework */; };
- 011CA09815D3144E007DBC54 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 011CA09615D3144E007DBC54 /* InfoPlist.strings */; };
- 011CA09A15D3144E007DBC54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 011CA09915D3144E007DBC54 /* main.m */; };
- 011CA09E15D3144E007DBC54 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 011CA09D15D3144E007DBC54 /* AppDelegate.m */; };
+ 0145C74115D3182F007244F3 /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0145C74015D3182F007244F3 /* MapKit.framework */; };
+ 0145C74615D32505007244F3 /* mars.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 0145C74515D32505007244F3 /* mars.jpg */; };
+ 017FD73F15D317B1006825B3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 017FD73D15D317A5006825B3 /* AppDelegate.m */; };
+ 017FD74015D317B1006825B3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 017FD73C15D3162C006825B3 /* main.m */; };
+ 01A6EE6515D49BD500E895D6 /* SMCalloutView.m in Sources */ = {isa = PBXBuildFile; fileRef = 01A6EE6415D49BD500E895D6 /* SMCalloutView.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
011CA08915D3144E007DBC54 /* CalloutViewSamples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CalloutViewSamples.app; sourceTree = BUILT_PRODUCTS_DIR; };
011CA08D15D3144E007DBC54 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
011CA08F15D3144E007DBC54 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
011CA09115D3144E007DBC54 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
- 011CA09515D3144E007DBC54 /* CalloutViewSamples-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CalloutViewSamples-Info.plist"; sourceTree = "<group>"; };
- 011CA09715D3144E007DBC54 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
- 011CA09915D3144E007DBC54 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
- 011CA09B15D3144E007DBC54 /* CalloutViewSamples-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CalloutViewSamples-Prefix.pch"; sourceTree = "<group>"; };
- 011CA09C15D3144E007DBC54 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
- 011CA09D15D3144E007DBC54 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ 0145C74015D3182F007244F3 /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; };
+ 0145C74515D32505007244F3 /* mars.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = mars.jpg; sourceTree = SOURCE_ROOT; };
+ 017FD73A15D3162C006825B3 /* CalloutViewSamples-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CalloutViewSamples-Info.plist"; sourceTree = SOURCE_ROOT; };
+ 017FD73B15D3162C006825B3 /* CalloutViewSamples-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CalloutViewSamples-Prefix.pch"; sourceTree = SOURCE_ROOT; };
+ 017FD73C15D3162C006825B3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = SOURCE_ROOT; };
+ 017FD73D15D317A5006825B3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = SOURCE_ROOT; };
+ 017FD73E15D317A5006825B3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = SOURCE_ROOT; };
+ 01A6EE6315D49BD500E895D6 /* SMCalloutView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SMCalloutView.h; path = ../SMCalloutView.h; sourceTree = "<group>"; };
+ 01A6EE6415D49BD500E895D6 /* SMCalloutView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SMCalloutView.m; path = ../SMCalloutView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
011CA08615D3144E007DBC54 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ 0145C74115D3182F007244F3 /* MapKit.framework in Frameworks */,
011CA08E15D3144E007DBC54 /* UIKit.framework in Frameworks */,
011CA09015D3144E007DBC54 /* Foundation.framework in Frameworks */,
011CA09215D3144E007DBC54 /* CoreGraphics.framework in Frameworks */,
@@ -45,7 +51,8 @@
011CA07E15D3144E007DBC54 = {
isa = PBXGroup;
children = (
- 011CA09315D3144E007DBC54 /* CalloutViewSamples */,
+ 0145C76615D48F0D007244F3 /* Callout View */,
+ 011CA09315D3144E007DBC54 /* Samples */,
011CA08C15D3144E007DBC54 /* Frameworks */,
011CA08A15D3144E007DBC54 /* Products */,
);
@@ -65,27 +72,38 @@
011CA08D15D3144E007DBC54 /* UIKit.framework */,
011CA08F15D3144E007DBC54 /* Foundation.framework */,
011CA09115D3144E007DBC54 /* CoreGraphics.framework */,
+ 0145C74015D3182F007244F3 /* MapKit.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
- 011CA09315D3144E007DBC54 /* CalloutViewSamples */ = {
+ 011CA09315D3144E007DBC54 /* Samples */ = {
isa = PBXGroup;
children = (
- 011CA09C15D3144E007DBC54 /* AppDelegate.h */,
- 011CA09D15D3144E007DBC54 /* AppDelegate.m */,
- 011CA09415D3144E007DBC54 /* Supporting Files */,
+ 017FD73E15D317A5006825B3 /* AppDelegate.h */,
+ 017FD73D15D317A5006825B3 /* AppDelegate.m */,
+ 017FD73915D31618006825B3 /* Supporting Files */,
);
+ name = Samples;
path = CalloutViewSamples;
sourceTree = "<group>";
};
- 011CA09415D3144E007DBC54 /* Supporting Files */ = {
+ 0145C76615D48F0D007244F3 /* Callout View */ = {
isa = PBXGroup;
children = (
- 011CA09515D3144E007DBC54 /* CalloutViewSamples-Info.plist */,
- 011CA09615D3144E007DBC54 /* InfoPlist.strings */,
- 011CA09915D3144E007DBC54 /* main.m */,
- 011CA09B15D3144E007DBC54 /* CalloutViewSamples-Prefix.pch */,
+ 01A6EE6315D49BD500E895D6 /* SMCalloutView.h */,
+ 01A6EE6415D49BD500E895D6 /* SMCalloutView.m */,
+ );
+ name = "Callout View";
+ sourceTree = "<group>";
+ };
+ 017FD73915D31618006825B3 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 017FD73A15D3162C006825B3 /* CalloutViewSamples-Info.plist */,
+ 017FD73B15D3162C006825B3 /* CalloutViewSamples-Prefix.pch */,
+ 017FD73C15D3162C006825B3 /* main.m */,
+ 0145C74515D32505007244F3 /* mars.jpg */,
);
name = "Supporting Files";
sourceTree = "<group>";
@@ -140,7 +158,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 011CA09815D3144E007DBC54 /* InfoPlist.strings in Resources */,
+ 0145C74615D32505007244F3 /* mars.jpg in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -151,24 +169,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 011CA09A15D3144E007DBC54 /* main.m in Sources */,
- 011CA09E15D3144E007DBC54 /* AppDelegate.m in Sources */,
+ 01A6EE6515D49BD500E895D6 /* SMCalloutView.m in Sources */,
+ 017FD73F15D317B1006825B3 /* AppDelegate.m in Sources */,
+ 017FD74015D317B1006825B3 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
-/* Begin PBXVariantGroup section */
- 011CA09615D3144E007DBC54 /* InfoPlist.strings */ = {
- isa = PBXVariantGroup;
- children = (
- 011CA09715D3144E007DBC54 /* en */,
- );
- name = InfoPlist.strings;
- sourceTree = "<group>";
- };
-/* End PBXVariantGroup section */
-
/* Begin XCBuildConfiguration section */
011CA09F15D3144E007DBC54 /* Debug */ = {
isa = XCBuildConfiguration;
@@ -225,8 +233,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
- GCC_PREFIX_HEADER = "CalloutViewSamples/CalloutViewSamples-Prefix.pch";
- INFOPLIST_FILE = "CalloutViewSamples/CalloutViewSamples-Info.plist";
+ GCC_PREFIX_HEADER = "CalloutViewSamples-Prefix.pch";
+ INFOPLIST_FILE = "CalloutViewSamples-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -236,8 +245,9 @@
isa = XCBuildConfiguration;
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
- GCC_PREFIX_HEADER = "CalloutViewSamples/CalloutViewSamples-Prefix.pch";
- INFOPLIST_FILE = "CalloutViewSamples/CalloutViewSamples-Info.plist";
+ GCC_PREFIX_HEADER = "CalloutViewSamples-Prefix.pch";
+ INFOPLIST_FILE = "CalloutViewSamples-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -262,6 +272,7 @@
011CA0A315D3144E007DBC54 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
File renamed without changes.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b3d169e

Please sign in to comment.