-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add view to capture and log taps as json coordinates
- Loading branch information
Showing
4 changed files
with
118 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// CoordinateReporter.h | ||
// GraceWorld | ||
// | ||
// Created by John Detloff on 5/4/13. | ||
// Copyright (c) 2013 Uebie. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@protocol CoordinateReporterDelegate <NSObject> | ||
- (NSDictionary *)attributesToReportForCoordinate:(CGPoint)coordinate; | ||
@end | ||
|
||
@interface CoordinateReporter : UIView | ||
@property (nonatomic, weak) id<CoordinateReporterDelegate>delegate; | ||
|
||
- (void)clear; | ||
- (void)print; | ||
|
||
@end |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// CoordinateReporter.m | ||
// GraceWorld | ||
// | ||
// Created by John Detloff on 5/4/13. | ||
// Copyright (c) 2013 Uebie. All rights reserved. | ||
// | ||
|
||
#import "CoordinateReporter.h" | ||
|
||
@implementation CoordinateReporter { | ||
NSMutableString *_coordinatesString; | ||
} | ||
|
||
|
||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { | ||
if (!_coordinatesString) { | ||
_coordinatesString = [@"" mutableCopy]; | ||
} | ||
|
||
UITouch *touch = [touches anyObject]; | ||
CGPoint point = [touch locationInView:self]; | ||
NSDictionary *propertyDict = [self.delegate attributesToReportForCoordinate:point]; | ||
|
||
NSMutableString *reportString = [@"{" mutableCopy]; | ||
|
||
[propertyDict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | ||
NSString *keyString = (NSString *)key; | ||
NSNumber *val = (NSNumber *)obj; | ||
[reportString appendFormat:@"\"%@\":%.2f,",keyString,[val floatValue]]; | ||
}]; | ||
[reportString replaceCharactersInRange:NSMakeRange([reportString length]-1, 1) withString:@""]; | ||
[reportString appendString:@"}"]; | ||
|
||
[_coordinatesString appendFormat:@"%@,\n",reportString]; | ||
} | ||
|
||
|
||
- (void)clear { | ||
_coordinatesString = nil; | ||
} | ||
|
||
|
||
- (void)print { | ||
NSLog(@"%@",_coordinatesString); | ||
} | ||
|
||
|
||
@end |
This file contains 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 characters