diff --git a/Classes/BITBlurImageAnnotation.m b/Classes/BITBlurImageAnnotation.m index 9d8f762cd2..983c49b891 100644 --- a/Classes/BITBlurImageAnnotation.m +++ b/Classes/BITBlurImageAnnotation.m @@ -12,6 +12,7 @@ @property (nonatomic, strong) CALayer* imageLayer; @property (nonatomic, strong) UIImage* scaledImage; +@property (nonatomic, strong) CALayer* selectedLayer; @end @@ -25,6 +26,13 @@ self.clipsToBounds = YES; self.imageLayer = [CALayer layer]; [self.layer addSublayer:self.imageLayer]; + + self.selectedLayer = [CALayer layer]; + [self.layer insertSublayer:self.selectedLayer above:self.imageLayer]; + + self.selectedLayer.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5f].CGColor; + self.selectedLayer.opacity = 0.6f; + self.clipsToBounds = YES; } return self; } @@ -33,6 +41,7 @@ CGSize size = CGSizeMake(sourceImage.size.width/30, sourceImage.size.height/30); UIGraphicsBeginImageContext(size); + [sourceImage drawInRect:CGRectMake(0, 0, size.width, size.height)]; self.scaledImage = UIGraphicsGetImageFromCurrentImageContext(); self.imageLayer.shouldRasterize = YES; @@ -40,11 +49,19 @@ self.imageLayer.magnificationFilter = kCAFilterNearest; self.imageLayer.contents = (id)self.scaledImage.CGImage; - - UIGraphicsEndImageContext(); } +- (void)setSelected:(BOOL)selected { + self->_selected = selected; + + if (selected){ + self.selectedLayer.opacity = 0.6f; + } else { + self.selectedLayer.opacity = 0.0f; + } +} + - (void)layoutSubviews { [super layoutSubviews]; @@ -54,6 +71,7 @@ self.imageLayer.frame = self.imageFrame; self.imageLayer.masksToBounds = YES; + self.selectedLayer.frame= self.bounds; [CATransaction commit]; } diff --git a/Classes/BITImageAnnotation.h b/Classes/BITImageAnnotation.h index f848ee2484..24d312e574 100644 --- a/Classes/BITImageAnnotation.h +++ b/Classes/BITImageAnnotation.h @@ -8,11 +8,17 @@ #import -@interface BITImageAnnotation : UIView +@interface BITImageAnnotation : UIView { + BOOL _selected; +} + @property (nonatomic) CGSize movedDelta; @property (nonatomic, weak) UIImage *sourceImage; @property (nonatomic) CGRect imageFrame; -(BOOL)resizable; +- (void)setSelected:(BOOL)selected; +- (BOOL)isSelected; + @end diff --git a/Classes/BITImageAnnotation.m b/Classes/BITImageAnnotation.m index d0e42614e3..473889a3ba 100644 --- a/Classes/BITImageAnnotation.m +++ b/Classes/BITImageAnnotation.m @@ -25,4 +25,12 @@ return NO; } +- (void)setSelected:(BOOL)selected { + self->_selected = selected; +} + +- (BOOL)isSelected { + return self->_selected; +} + @end diff --git a/Classes/BITImageAnnotationViewController.m b/Classes/BITImageAnnotationViewController.m index 714080d2e9..9ff33cb2d4 100644 --- a/Classes/BITImageAnnotationViewController.m +++ b/Classes/BITImageAnnotationViewController.m @@ -161,7 +161,13 @@ #pragma mark - Gesture Handling - (void)panned:(UIPanGestureRecognizer *)gestureRecognizer { - if ([self.editingControls selectedSegmentIndex] != UISegmentedControlNoSegment || self.isDrawing ){ + BITImageAnnotation *annotationAtLocation = (BITImageAnnotation *)[self.view hitTest:[gestureRecognizer locationInView:self.view] withEvent:nil]; + + if (![annotationAtLocation isKindOfClass:[BITImageAnnotation class]]){ + annotationAtLocation = nil; + } + + if (([self.editingControls selectedSegmentIndex] != UISegmentedControlNoSegment || self.isDrawing) && !annotationAtLocation ){ if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ self.currentAnnotation = [self annotationForCurrentMode]; [self.objects addObject:self.currentAnnotation]; @@ -192,11 +198,14 @@ } else { if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ // find and possibly move an existing annotation. - BITImageAnnotation *selectedAnnotation = (BITImageAnnotation *)[self.view hitTest:[gestureRecognizer locationInView:self.view] withEvent:nil]; + - if ([self.objects indexOfObject:selectedAnnotation] != NSNotFound){ - self.currentAnnotation = selectedAnnotation; + if ([self.objects indexOfObject:annotationAtLocation] != NSNotFound){ + self.currentAnnotation = annotationAtLocation; + [annotationAtLocation setSelected:YES]; } + + } else if (gestureRecognizer.state == UIGestureRecognizerStateChanged && self.currentAnnotation){ CGPoint delta = [gestureRecognizer translationInView:self.view]; @@ -213,6 +222,8 @@ } else { self.currentAnnotation = nil; + [annotationAtLocation setSelected:NO]; + } } }