From 41d205f661ffbf9b6dc994bf951946681b971967 Mon Sep 17 00:00:00 2001 From: Robin Trigodet Date: Thu, 26 Mar 2015 12:37:55 +0100 Subject: [PATCH 1/3] Add the possibility to add bezier path on the map --- Demo/JCTiledViewDemo/RootViewController.m | 69 ++++++++++++++++---- Headers/JCTiledScrollView.h | 6 ++ JCTiledScrollView/Source/JCTiledScrollView.m | 47 +++++++++++++ 3 files changed, 109 insertions(+), 13 deletions(-) diff --git a/Demo/JCTiledViewDemo/RootViewController.m b/Demo/JCTiledViewDemo/RootViewController.m index 3da1a429..06b4e350 100644 --- a/Demo/JCTiledViewDemo/RootViewController.m +++ b/Demo/JCTiledViewDemo/RootViewController.m @@ -19,6 +19,11 @@ #import "JCTiledView.h" #endif +@interface RootViewController () + +@property (nonatomic, strong) NSArray *bezierPaths; +@end + @implementation RootViewController @@ -67,9 +72,10 @@ - (void)viewDidLoad addButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; [addButton addTarget:self action:@selector(addRandomAnnotations) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:addButton]; - + [self tiledScrollViewDidZoom:self.scrollView]; //force the detailView to update the frist time [self addRandomAnnotations]; + } - (void)viewDidUnload @@ -115,18 +121,40 @@ - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event - (void)addRandomAnnotations { - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - srand(42); - }); - - CGSize size = SkippingGirlImageSize; - for (int i = 0; i < 5; i++) - { - id a = [[DemoAnnotation alloc] init]; - a.contentPosition = CGPointMake((float)(rand() % (int)size.width), (float)(rand() % (int)size.height)); - [self.scrollView addAnnotation:a]; - } + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + srand(42); + }); + + CGSize size = SkippingGirlImageSize; + + NSMutableArray *paths = [NSMutableArray array]; + + for (int i = 0; i < 5; i++) + { + + } + for (int i = 0; i < 6/2; i++) { + + id firstAnnot = [[DemoAnnotation alloc] init]; + CGPoint firstContentPosition = CGPointMake((float)(rand() % (int)size.width), (float)(rand() % (int)size.height)); + firstAnnot.contentPosition = firstContentPosition; + id secondAnnot = [[DemoAnnotation alloc] init]; + CGPoint secondContentPosition = CGPointMake((float)(rand() % (int)size.width), (float)(rand() % (int)size.height)); + secondAnnot.contentPosition = secondContentPosition; + [self.scrollView addAnnotation:firstAnnot]; + [self.scrollView addAnnotation:secondAnnot]; + + + UIBezierPath *path = [UIBezierPath bezierPath]; + [path moveToPoint:CGPointMake(firstContentPosition.x, firstContentPosition.y + 30.f)]; // 30.f is max height of the annotation image + [path addLineToPoint:CGPointMake(secondContentPosition.x, secondContentPosition.y + 30.f)]; // 30.f is max height of the annotation image + path.lineWidth = 3.f; + [paths addObject:path]; + } + + self.bezierPaths = [NSArray arrayWithArray:paths]; + } #pragma mark - JCTiledScrollViewDelegate @@ -169,4 +197,19 @@ - (UIImage *)tiledScrollView:(JCTiledScrollView *)scrollView imageForRow:(NSInte } +-(UIBezierPath *)tiledScrollViewGetBezierPath:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index{ + return [self.bezierPaths objectAtIndex:index]; +} + +- (UIColor *)tiledScrollViewGetPathColor:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index { + //UIColor *color = [UIColor colorWithRed:38.f/255.f green:166.f/255.f blue:91.f/255.f alpha:1.f]; + UIColor *color = [UIColor whiteColor]; + return color; +} + +- (NSInteger)tiledScrollViewGetNumberOfPath:(JCTiledScrollView *)scrollView { + return [self.bezierPaths count]; +} + + @end diff --git a/Headers/JCTiledScrollView.h b/Headers/JCTiledScrollView.h index 80aaa866..5ac59581 100755 --- a/Headers/JCTiledScrollView.h +++ b/Headers/JCTiledScrollView.h @@ -56,6 +56,12 @@ - (void)tiledScrollView:(JCTiledScrollView *)scrollView didReceiveDoubleTap:(UIGestureRecognizer *)gestureRecognizer; - (void)tiledScrollView:(JCTiledScrollView *)scrollView didReceiveTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer; +- (UIBezierPath *)tiledScrollViewGetBezierPath:(JCTiledScrollView *)scrollView ; +- (UIColor *)tiledScrollViewGetPathColor:(JCTiledScrollView *)scrollView ; +- (UIBezierPath *)tiledScrollViewGetBezierPath:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index; +- (UIColor *)tiledScrollViewGetPathColor:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index; +- (NSInteger)tiledScrollViewGetNumberOfPath:(JCTiledScrollView *)scrollView; + @end @interface JCTiledScrollView : UIView diff --git a/JCTiledScrollView/Source/JCTiledScrollView.m b/JCTiledScrollView/Source/JCTiledScrollView.m index 6f430271..523cbd44 100755 --- a/JCTiledScrollView/Source/JCTiledScrollView.m +++ b/JCTiledScrollView/Source/JCTiledScrollView.m @@ -42,6 +42,7 @@ @interface JCTiledScrollView () )annotation @@ -563,4 +569,45 @@ - (void)removeAllAnnotations [self removeAnnotations:[_annotations allObjects]]; } +#pragma mark - PATH +- (void)addPath { + if([self.tiledScrollViewDelegate respondsToSelector:@selector(tiledScrollViewGetBezierPath:)]){ + UIBezierPath *path = [self.tiledScrollViewDelegate tiledScrollViewGetBezierPath:self]; + [self addPath:path andColor:[self.tiledScrollViewDelegate tiledScrollViewGetPathColor:self]]; + } + else if ([self.tiledScrollViewDelegate respondsToSelector:@selector(tiledScrollViewGetNumberOfPath:)]) { + for (CALayer *layer in [_tiledView.layer sublayers]) { + [layer removeFromSuperlayer]; + } + int number = (int)[self.tiledScrollViewDelegate tiledScrollViewGetNumberOfPath:self]; + for (int i = 0; i < number; i++) { + UIColor *color = [UIColor blackColor]; + UIBezierPath *path = nil; + if([self.tiledScrollViewDelegate respondsToSelector:@selector(tiledScrollViewGetBezierPath:atIndex:)]){ + path = [self.tiledScrollViewDelegate tiledScrollViewGetBezierPath:self atIndex:i]; + } + if([self.tiledScrollViewDelegate respondsToSelector:@selector(tiledScrollViewGetPathColor:atIndex:)]){ + color = [self.tiledScrollViewDelegate tiledScrollViewGetPathColor:self atIndex:i]; + } + [self addPath:path andColor:color]; + } + } +} + +- (void)addPath:(UIBezierPath *)path andColor:(UIColor *)color { + if (!self.pathLayers) self.pathLayers = [NSMutableArray array]; + if (path) { + CAShapeLayer *pathLayr = [CAShapeLayer layer]; + pathLayr.anchorPoint = CGPointMake(0.5, 0.5); + pathLayr.frame = self.tiledView.frame; + pathLayr.path = path.CGPath; + pathLayr.strokeColor = (color?color:[UIColor blackColor]).CGColor; + pathLayr.fillColor = [UIColor clearColor].CGColor; + pathLayr.lineWidth = path.lineWidth; + pathLayr.lineJoin = kCALineJoinBevel; + [_tiledView.layer addSublayer:pathLayr]; + [self.pathLayers addObject:pathLayr]; + } +} + @end From 2994d9925ce3a762947da3f11d38e61f0c0d7fcd Mon Sep 17 00:00:00 2001 From: Robin Trigodet Date: Thu, 26 Mar 2015 14:43:36 +0100 Subject: [PATCH 2/3] Removing unused function --- Headers/JCTiledScrollView.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Headers/JCTiledScrollView.h b/Headers/JCTiledScrollView.h index 5ac59581..7febfdb8 100755 --- a/Headers/JCTiledScrollView.h +++ b/Headers/JCTiledScrollView.h @@ -56,8 +56,6 @@ - (void)tiledScrollView:(JCTiledScrollView *)scrollView didReceiveDoubleTap:(UIGestureRecognizer *)gestureRecognizer; - (void)tiledScrollView:(JCTiledScrollView *)scrollView didReceiveTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer; -- (UIBezierPath *)tiledScrollViewGetBezierPath:(JCTiledScrollView *)scrollView ; -- (UIColor *)tiledScrollViewGetPathColor:(JCTiledScrollView *)scrollView ; - (UIBezierPath *)tiledScrollViewGetBezierPath:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index; - (UIColor *)tiledScrollViewGetPathColor:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index; - (NSInteger)tiledScrollViewGetNumberOfPath:(JCTiledScrollView *)scrollView; From 837b4e37f4ea384f00c71df5c51280cbee4fa729 Mon Sep 17 00:00:00 2001 From: Robin Trigodet Date: Thu, 26 Mar 2015 14:53:20 +0100 Subject: [PATCH 3/3] Removing unused loop --- Demo/JCTiledViewDemo/RootViewController.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Demo/JCTiledViewDemo/RootViewController.m b/Demo/JCTiledViewDemo/RootViewController.m index 06b4e350..9ec5df65 100644 --- a/Demo/JCTiledViewDemo/RootViewController.m +++ b/Demo/JCTiledViewDemo/RootViewController.m @@ -130,10 +130,6 @@ - (void)addRandomAnnotations NSMutableArray *paths = [NSMutableArray array]; - for (int i = 0; i < 5; i++) - { - - } for (int i = 0; i < 6/2; i++) { id firstAnnot = [[DemoAnnotation alloc] init];