diff --git a/Classes/BITArrowImageAnnotation.m b/Classes/BITArrowImageAnnotation.m index ae9d6b34fe..fee2b8a254 100644 --- a/Classes/BITArrowImageAnnotation.m +++ b/Classes/BITArrowImageAnnotation.m @@ -26,12 +26,12 @@ self = [super initWithFrame:frame]; if (self) { self.shapeLayer = [CAShapeLayer layer]; - self.shapeLayer.strokeColor = [UIColor redColor].CGColor; + self.shapeLayer.strokeColor = [UIColor whiteColor].CGColor; self.shapeLayer.lineWidth = 5; - self.shapeLayer.fillColor = [UIColor clearColor].CGColor; + self.shapeLayer.fillColor = [UIColor redColor].CGColor; self.strokeLayer = [CAShapeLayer layer]; - self.strokeLayer.strokeColor = [UIColor whiteColor].CGColor; + self.strokeLayer.strokeColor = [UIColor redColor].CGColor; self.strokeLayer.lineWidth = 10; self.strokeLayer.fillColor = [UIColor clearColor].CGColor; [self.layer addSublayer:self.strokeLayer]; @@ -154,4 +154,39 @@ return (CGAffineTransform){ cosine, sine, -sine, cosine, startPoint.x, startPoint.y }; } +#pragma mark - UIView + +- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { + UIColor *color = [self colorAtPoint:point]; + CGFloat alpha, white; + [color getWhite:&white alpha:&alpha]; + if (white || alpha){ + return self; + } else { + return nil; + } + +} + +#pragma mark - Helpers + +// This is taken from http://stackoverflow.com/questions/12770181/how-to-get-the-pixel-color-on-touch +- (UIColor *)colorAtPoint:(CGPoint)point { + unsigned char pixel[4] = {0}; + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGContextRef context = CGBitmapContextCreate(pixel, + 1, 1, 8, 4, colorSpace, (CGBitmapInfo)kCGImageAlphaPremultipliedLast); + + CGContextTranslateCTM(context, -point.x, -point.y); + + [self.layer renderInContext:context]; + + CGContextRelease(context); + CGColorSpaceRelease(colorSpace); + UIColor *color = [UIColor colorWithRed:pixel[0]/255.0 + green:pixel[1]/255.0 blue:pixel[2]/255.0 + alpha:pixel[3]/255.0]; + return color; +} + @end diff --git a/Classes/BITImageAnnotationViewController.m b/Classes/BITImageAnnotationViewController.m index 9ff33cb2d4..0974412967 100644 --- a/Classes/BITImageAnnotationViewController.m +++ b/Classes/BITImageAnnotationViewController.m @@ -14,6 +14,12 @@ #import "BITHockeyHelper.h" #import "HockeySDKPrivate.h" +typedef NS_ENUM(NSInteger, BITImageAnnotationViewControllerInteractionMode) { + BITImageAnnotationViewControllerInteractionModeNone, + BITImageAnnotationViewControllerInteractionModeDraw, + BITImageAnnotationViewControllerInteractionModeMove +}; + @interface BITImageAnnotationViewController () @property (nonatomic, strong) UIImageView *imageView; @@ -29,7 +35,7 @@ @property (nonatomic) CGPoint panStart; @property (nonatomic,strong) BITImageAnnotation *currentAnnotation; -@property (nonatomic) BOOL isDrawing; +@property (nonatomic) BITImageAnnotationViewControllerInteractionMode currentInteraction; @property (nonatomic) CGRect pinchStartingFrame; @@ -158,7 +164,7 @@ return renderedImageOfMyself; } -#pragma mark - Gesture Handling +#pragma mark - UIGestureRecognizers - (void)panned:(UIPanGestureRecognizer *)gestureRecognizer { BITImageAnnotation *annotationAtLocation = (BITImageAnnotation *)[self.view hitTest:[gestureRecognizer locationInView:self.view] withEvent:nil]; @@ -167,7 +173,22 @@ annotationAtLocation = nil; } - if (([self.editingControls selectedSegmentIndex] != UISegmentedControlNoSegment || self.isDrawing) && !annotationAtLocation ){ + // determine the interaction mode if none is set so far. + + if (self.currentInteraction == BITImageAnnotationViewControllerInteractionModeNone){ + if (annotationAtLocation){ + self.currentInteraction = BITImageAnnotationViewControllerInteractionModeMove; + } else if ([self canDrawNewAnnotation]){ + self.currentInteraction = BITImageAnnotationViewControllerInteractionModeDraw; + } + } + + if (self.currentInteraction == BITImageAnnotationViewControllerInteractionModeNone){ + return; + } + + + if (self.currentInteraction == BITImageAnnotationViewControllerInteractionModeDraw){ if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ self.currentAnnotation = [self annotationForCurrentMode]; [self.objects addObject:self.currentAnnotation]; @@ -182,7 +203,6 @@ self.panStart = [gestureRecognizer locationInView:self.imageView]; // [self.editingControls setSelectedSegmentIndex:UISegmentedControlNoSegment]; - self.isDrawing = YES; } else if (gestureRecognizer.state == UIGestureRecognizerStateChanged){ CGPoint bla = [gestureRecognizer locationInView:self.imageView]; @@ -193,9 +213,9 @@ [self.currentAnnotation layoutIfNeeded]; } else { self.currentAnnotation = nil; - self.isDrawing = NO; + self.currentInteraction = BITImageAnnotationViewControllerInteractionModeNone; } - } else { + } else if (self.currentInteraction == BITImageAnnotationViewControllerInteractionModeMove){ if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ // find and possibly move an existing annotation. @@ -223,6 +243,8 @@ } else { self.currentAnnotation = nil; [annotationAtLocation setSelected:NO]; + self.currentInteraction = BITImageAnnotationViewControllerInteractionModeNone; + } } @@ -281,15 +303,12 @@ -(void)tapped:(UIGestureRecognizer *)tapRecognizer { if (self.navigationController.navigationBarHidden){ - // [[UIApplication sharedApplication] setStatusBarHidden:NO]; [UIView animateWithDuration:0.35f animations:^{ self.navigationController.navigationBar.alpha = 1; } completion:^(BOOL finished) { [self fitImageViewFrame]; [self.navigationController setNavigationBarHidden:NO animated:NO]; [[UIApplication sharedApplication] setStatusBarHidden:NO]; - - }]; } else { [UIView animateWithDuration:0.35f animations:^{ @@ -319,4 +338,7 @@ return self.imageView; } +- (BOOL)canDrawNewAnnotation { + return [self.editingControls selectedSegmentIndex] != UISegmentedControlNoSegment; +} @end