From ad086273d7349b766047e2329c7618ecf2e0357e Mon Sep 17 00:00:00 2001 From: moritz haarmann Date: Wed, 26 Feb 2014 15:22:44 +0100 Subject: [PATCH] + Replicated Bugshot. --- Classes/BITArrowImageAnnotation.m | 39 ++++++++++++-- Classes/BITBlurImageAnnotation.h | 13 +++++ Classes/BITBlurImageAnnotation.m | 57 +++++++++++++++++++++ Classes/BITImageAnnotation.h | 4 +- Classes/BITImageAnnotationViewController.m | 17 +++--- Classes/BITRectangleImageAnnotation.m | 13 +++++ Support/HockeySDK.xcodeproj/project.pbxproj | 8 +++ 7 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 Classes/BITBlurImageAnnotation.h create mode 100644 Classes/BITBlurImageAnnotation.m diff --git a/Classes/BITArrowImageAnnotation.m b/Classes/BITArrowImageAnnotation.m index 472b5a019a..b53bb502ff 100644 --- a/Classes/BITArrowImageAnnotation.m +++ b/Classes/BITArrowImageAnnotation.m @@ -14,6 +14,8 @@ @interface BITArrowImageAnnotation() @property (nonatomic, strong) CAShapeLayer *shapeLayer; +@property (nonatomic, strong) CAShapeLayer *strokeLayer; + @end @@ -27,7 +29,15 @@ self.shapeLayer.strokeColor = [UIColor redColor].CGColor; self.shapeLayer.lineWidth = 5; self.shapeLayer.fillColor = [UIColor clearColor].CGColor; + + self.strokeLayer = [CAShapeLayer layer]; + self.strokeLayer.strokeColor = [UIColor whiteColor].CGColor; + self.strokeLayer.lineWidth = 10; + self.strokeLayer.fillColor = [UIColor clearColor].CGColor; + [self.layer addSublayer:self.strokeLayer]; + [self.layer addSublayer:self.shapeLayer]; + } return self; @@ -35,20 +45,41 @@ - (void)buildShape { CGFloat topHeight = MAX(self.frame.size.width / 3.0f,20); + - CGFloat lineWidth = MAX(self.frame.size.width / 5.0f,20); + CGFloat lineWidth = MAX(self.frame.size.width / 10.0f,10); + CGFloat startX, startY, endX, endY; + if ( self.movedDelta.width > 0){ + startX = CGRectGetMinX(self.bounds); + endX = CGRectGetMaxX(self.bounds); + } else { + startX = CGRectGetMaxX(self.bounds); + endX = CGRectGetMinX(self.bounds); + + } - UIBezierPath *path = [self bezierPathWithArrowFromPoint:CGPointMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame)) toPoint:CGPointMake(CGRectGetMaxX(self.frame), CGRectGetMaxY(self.frame)) tailWidth:lineWidth headWidth:self.frame.size.height headLength:topHeight]; + if ( self.movedDelta.height > 0){ + startY = CGRectGetMinY(self.bounds); + endY = CGRectGetMaxY(self.bounds); + } else { + startY = CGRectGetMaxY(self.bounds); + endY = CGRectGetMinY(self.bounds); + + } + + NSLog(@"Start X: %f, Y: %f, END: %f %f %@", startX, startY, endX,endY, self); + + UIBezierPath *path = [self bezierPathWithArrowFromPoint:CGPointMake(endX,endY) toPoint:CGPointMake(startX,startY) tailWidth:lineWidth headWidth:topHeight headLength:topHeight]; self.shapeLayer.path = path.CGPath; + self.strokeLayer.path = path.CGPath; } -(void)layoutSubviews{ [super layoutSubviews]; - + [self buildShape]; - self.shapeLayer.frame = self.bounds; } /* diff --git a/Classes/BITBlurImageAnnotation.h b/Classes/BITBlurImageAnnotation.h new file mode 100644 index 0000000000..b23d7f2d82 --- /dev/null +++ b/Classes/BITBlurImageAnnotation.h @@ -0,0 +1,13 @@ +// +// BITBlurImageAnnotation.h +// HockeySDK +// +// Created by Moritz Haarmann on 26.02.14. +// +// + +#import "BITImageAnnotation.h" + +@interface BITBlurImageAnnotation : BITImageAnnotation + +@end diff --git a/Classes/BITBlurImageAnnotation.m b/Classes/BITBlurImageAnnotation.m new file mode 100644 index 0000000000..898ce2a3c8 --- /dev/null +++ b/Classes/BITBlurImageAnnotation.m @@ -0,0 +1,57 @@ +// +// BITBlurImageAnnotation.m +// HockeySDK +// +// Created by Moritz Haarmann on 26.02.14. +// +// + +#import "BITBlurImageAnnotation.h" + +@interface BITBlurImageAnnotation() + +@property (nonatomic, strong) CALayer* imageLayer; +@property (nonatomic, strong) UIImage* scaledImage; + + +@end + +@implementation BITBlurImageAnnotation + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + self.clipsToBounds = YES; + self.imageLayer = [CALayer layer]; + [self.layer addSublayer:self.imageLayer]; + } + return self; +} + +-(void)setSourceImage:(UIImage *)sourceImage { + 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.contents = (id)self.scaledImage.CGImage; + UIGraphicsEndImageContext(); +} + +- (void)layoutSubviews { + [super layoutSubviews]; + self.imageLayer.frame = self.imageFrame; + self.imageLayer.masksToBounds = YES; +} + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect +{ + // Drawing code +} +*/ + +@end diff --git a/Classes/BITImageAnnotation.h b/Classes/BITImageAnnotation.h index 51e3a8c634..6449301275 100644 --- a/Classes/BITImageAnnotation.h +++ b/Classes/BITImageAnnotation.h @@ -9,5 +9,7 @@ #import @interface BITImageAnnotation : UIView - +@property (nonatomic) CGSize movedDelta; +@property (nonatomic, weak) UIImage *sourceImage; +@property (nonatomic) CGRect imageFrame; @end diff --git a/Classes/BITImageAnnotationViewController.m b/Classes/BITImageAnnotationViewController.m index 2f37b351e8..f997706023 100644 --- a/Classes/BITImageAnnotationViewController.m +++ b/Classes/BITImageAnnotationViewController.m @@ -10,6 +10,7 @@ #import "BITImageAnnotation.h" #import "BITRectangleImageAnnotation.h" #import "BITArrowImageAnnotation.h" +#import "BITBlurImageAnnotation.h" @interface BITImageAnnotationViewController () @@ -50,15 +51,12 @@ self.objects = [NSMutableArray new]; [self.editingControls addTarget:self action:@selector(editingAction:) forControlEvents:UIControlEventTouchUpInside]; + [self.editingControls setSelectedSegmentIndex:0]; self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; - - self.imageView.clipsToBounds = YES; - - self.imageView.layer.masksToBounds = YES; - + self.imageView.image = self.image; self.imageView.contentMode = UIViewContentModeScaleToFill; @@ -102,7 +100,7 @@ } else if(self.editingControls.selectedSegmentIndex==1){ return [[BITArrowImageAnnotation alloc] initWithFrame:CGRectZero]; } else { - return [[BITImageAnnotation alloc] initWithFrame:CGRectZero]; + return [[BITBlurImageAnnotation alloc] initWithFrame:CGRectZero]; } } @@ -143,11 +141,14 @@ if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ self.currentAnnotation = [self annotationForCurrentMode]; [self.objects addObject:self.currentAnnotation]; + self.currentAnnotation.sourceImage = self.image; [self.imageView insertSubview:self.currentAnnotation aboveSubview:self.imageView]; self.panStart = [gestureRecognizer locationInView:self.imageView]; } else if (gestureRecognizer.state == UIGestureRecognizerStateChanged){ - CGPoint bla = [gestureRecognizer translationInView:self.imageView]; - self.currentAnnotation.frame = CGRectMake(self.panStart.x, self.panStart.y, bla.x, bla.y); + CGPoint bla = [gestureRecognizer locationInView:self.imageView]; + self.currentAnnotation.frame = CGRectMake(self.panStart.x, self.panStart.y, bla.x - self.panStart.x, bla.y - self.panStart.y); + self.currentAnnotation.movedDelta = CGSizeMake(bla.x - self.panStart.x, bla.y - self.panStart.y); + self.currentAnnotation.imageFrame = [self.view convertRect:self.imageView.frame toView:self.currentAnnotation]; } } diff --git a/Classes/BITRectangleImageAnnotation.m b/Classes/BITRectangleImageAnnotation.m index 465008fec2..5fd44c7536 100644 --- a/Classes/BITRectangleImageAnnotation.m +++ b/Classes/BITRectangleImageAnnotation.m @@ -11,6 +11,8 @@ @interface BITRectangleImageAnnotation() @property (nonatomic, strong) CAShapeLayer *shapeLayer; +@property (nonatomic, strong) CAShapeLayer *strokeLayer; + @end @@ -24,6 +26,13 @@ self.shapeLayer.strokeColor = [UIColor redColor].CGColor; self.shapeLayer.lineWidth = 5; self.shapeLayer.fillColor = [UIColor clearColor].CGColor; + + self.strokeLayer = [CAShapeLayer layer]; + self.strokeLayer.strokeColor = [UIColor whiteColor].CGColor; + self.strokeLayer.lineWidth = 10; + self.strokeLayer.fillColor = [UIColor clearColor].CGColor; + [self.layer addSublayer:self.strokeLayer]; + [self.layer addSublayer:self.shapeLayer]; } @@ -35,6 +44,10 @@ self.shapeLayer.frame = self.bounds; self.shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10].CGPath; + + + self.strokeLayer.frame = self.bounds; + self.strokeLayer.path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10].CGPath; } /* diff --git a/Support/HockeySDK.xcodeproj/project.pbxproj b/Support/HockeySDK.xcodeproj/project.pbxproj index a2bce9973d..bf311915aa 100644 --- a/Support/HockeySDK.xcodeproj/project.pbxproj +++ b/Support/HockeySDK.xcodeproj/project.pbxproj @@ -136,6 +136,8 @@ 973EC8B818BCA8A200DBFFBB /* BITRectangleImageAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 973EC8B618BCA8A200DBFFBB /* BITRectangleImageAnnotation.m */; }; 973EC8BB18BDE29800DBFFBB /* BITArrowImageAnnotation.h in Headers */ = {isa = PBXBuildFile; fileRef = 973EC8B918BDE29800DBFFBB /* BITArrowImageAnnotation.h */; }; 973EC8BC18BDE29800DBFFBB /* BITArrowImageAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 973EC8BA18BDE29800DBFFBB /* BITArrowImageAnnotation.m */; }; + 973EC8BF18BE2B5B00DBFFBB /* BITBlurImageAnnotation.h in Headers */ = {isa = PBXBuildFile; fileRef = 973EC8BD18BE2B5B00DBFFBB /* BITBlurImageAnnotation.h */; }; + 973EC8C018BE2B5B00DBFFBB /* BITBlurImageAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 973EC8BE18BE2B5B00DBFFBB /* BITBlurImageAnnotation.m */; }; 9760F6C418BB4D2D00959B93 /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9760F6C318BB4D2D00959B93 /* AssetsLibrary.framework */; }; 9760F6CF18BB685600959B93 /* BITImageAnnotation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9760F6CD18BB685600959B93 /* BITImageAnnotation.h */; }; 9760F6D018BB685600959B93 /* BITImageAnnotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 9760F6CE18BB685600959B93 /* BITImageAnnotation.m */; }; @@ -304,6 +306,8 @@ 973EC8B618BCA8A200DBFFBB /* BITRectangleImageAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITRectangleImageAnnotation.m; sourceTree = ""; }; 973EC8B918BDE29800DBFFBB /* BITArrowImageAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITArrowImageAnnotation.h; sourceTree = ""; }; 973EC8BA18BDE29800DBFFBB /* BITArrowImageAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITArrowImageAnnotation.m; sourceTree = ""; }; + 973EC8BD18BE2B5B00DBFFBB /* BITBlurImageAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITBlurImageAnnotation.h; sourceTree = ""; }; + 973EC8BE18BE2B5B00DBFFBB /* BITBlurImageAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITBlurImageAnnotation.m; sourceTree = ""; }; 9760F6C318BB4D2D00959B93 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; 9760F6CD18BB685600959B93 /* BITImageAnnotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITImageAnnotation.h; sourceTree = ""; }; 9760F6CE18BB685600959B93 /* BITImageAnnotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITImageAnnotation.m; sourceTree = ""; }; @@ -570,6 +574,8 @@ 973EC8B618BCA8A200DBFFBB /* BITRectangleImageAnnotation.m */, 973EC8B918BDE29800DBFFBB /* BITArrowImageAnnotation.h */, 973EC8BA18BDE29800DBFFBB /* BITArrowImageAnnotation.m */, + 973EC8BD18BE2B5B00DBFFBB /* BITBlurImageAnnotation.h */, + 973EC8BE18BE2B5B00DBFFBB /* BITBlurImageAnnotation.m */, ); name = "Image Editor"; sourceTree = ""; @@ -684,6 +690,7 @@ 1E49A4731612226D00463151 /* BITUpdateManager.h in Headers */, 1E49A4791612226D00463151 /* BITUpdateManagerDelegate.h in Headers */, 1E49A44E1612223B00463151 /* BITFeedbackManager.h in Headers */, + 973EC8BF18BE2B5B00DBFFBB /* BITBlurImageAnnotation.h in Headers */, E4B4DB7D17B435550099C67F /* BITAuthenticationViewController.h in Headers */, 1E49A4481612223B00463151 /* BITFeedbackListViewController.h in Headers */, 1E49A47F1612226D00463151 /* BITUpdateViewController.h in Headers */, @@ -935,6 +942,7 @@ 1E49A4821612226D00463151 /* BITUpdateViewController.m in Sources */, E4B4DB7E17B435550099C67F /* BITAuthenticationViewController.m in Sources */, 1E49A4B2161222B900463151 /* BITHockeyBaseManager.m in Sources */, + 973EC8C018BE2B5B00DBFFBB /* BITBlurImageAnnotation.m in Sources */, 9760F6D018BB685600959B93 /* BITImageAnnotation.m in Sources */, 1E49A4BB161222B900463151 /* BITHockeyBaseViewController.m in Sources */, 97F0FA0518B2294D00EF50AA /* BITFeedbackMessageAttachment.m in Sources */,