Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 52 additions & 13 deletions Demo/JCTiledViewDemo/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#import "JCTiledView.h"
#endif

@interface RootViewController ()

@property (nonatomic, strong) NSArray *bezierPaths;
@end

@implementation RootViewController


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -115,18 +121,36 @@ - (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<JCAnnotation> 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 < 6/2; i++) {

id<JCAnnotation> firstAnnot = [[DemoAnnotation alloc] init];
CGPoint firstContentPosition = CGPointMake((float)(rand() % (int)size.width), (float)(rand() % (int)size.height));
firstAnnot.contentPosition = firstContentPosition;
id<JCAnnotation> 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
Expand Down Expand Up @@ -169,4 +193,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
4 changes: 4 additions & 0 deletions Headers/JCTiledScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
- (void)tiledScrollView:(JCTiledScrollView *)scrollView didReceiveDoubleTap:(UIGestureRecognizer *)gestureRecognizer;
- (void)tiledScrollView:(JCTiledScrollView *)scrollView didReceiveTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer;

- (UIBezierPath *)tiledScrollViewGetBezierPath:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index;
- (UIColor *)tiledScrollViewGetPathColor:(JCTiledScrollView *)scrollView atIndex:(NSInteger)index;
- (NSInteger)tiledScrollViewGetNumberOfPath:(JCTiledScrollView *)scrollView;

@end

@interface JCTiledScrollView : UIView <UIScrollViewDelegate>
Expand Down
47 changes: 47 additions & 0 deletions JCTiledScrollView/Source/JCTiledScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ @interface JCTiledScrollView () <JCTiledBitmapViewDelegate, UIGestureRecognizerD
@property (nonatomic, strong) UITapGestureRecognizer *doubleTapGestureRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *twoFingerTapGestureRecognizer;
@property (nonatomic, assign) BOOL muteAnnotationUpdates;
@property (nonatomic, strong) NSMutableArray *pathLayers;
@end

@implementation JCTiledScrollView
Expand Down Expand Up @@ -133,6 +134,10 @@ - (id)initWithFrame:(CGRect)frame contentSize:(CGSize)contentSize
return self;
}

-(void)didMoveToSuperview{
[super didMoveToSuperview];
[self addPath];
}

#pragma mark - UIScrolViewDelegate

Expand Down Expand Up @@ -507,6 +512,7 @@ - (BOOL)point:(CGPoint)point isWithinBounds:(CGRect)bounds
- (void)refreshAnnotations
{
[self correctScreenPositionOfAnnotations];
[self addPath];
}

- (void)addAnnotation:(id<JCAnnotation>)annotation
Expand Down Expand Up @@ -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