+ Some basic image editing functionality.

This commit is contained in:
moritz haarmann
2014-02-25 15:07:59 +01:00
parent 70e2b6635c
commit 28eee0eb3d
11 changed files with 261 additions and 9 deletions

View File

@@ -7,12 +7,19 @@
//
#import "BITImageAnnotationViewController.h"
#import "BITImageAnnotation.h"
#import "BITRectangleImageAnnotation.h"
@interface BITImageAnnotationViewController ()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UISegmentedControl *editingControls;
@property (nonatomic, strong) NSMutableArray *layers;
@property (nonatomic, strong) NSMutableArray *objects;
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
@property (nonatomic) CGPoint panStart;
@property (nonatomic,strong) BITImageAnnotation *currentAnnotation;
@end
@@ -41,11 +48,78 @@
self.imageView.image = self.image;
self.imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:self.imageView];
self.imageView.frame = self.view.bounds;
self.tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
self.panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panned:)];
[self.tapRecognizer requireGestureRecognizerToFail:self.panRecognizer];
[self.view addGestureRecognizer:self.tapRecognizer];
[self.view addGestureRecognizer:self.panRecognizer];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc ] initWithTitle:@"Discard" style:UIBarButtonItemStyleBordered target:self action:@selector(discard:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc ] initWithTitle:@"Save" style:UIBarButtonItemStyleBordered target:self action:@selector(save:)];
// Do any additional setup after loading the view.
}
-(void)editingAction:(id)sender {
}
- (BITImageAnnotation *)annotationForCurrentMode {
if (self.editingControls.selectedSegmentIndex == 0){
return [[BITRectangleImageAnnotation alloc] initWithFrame:CGRectZero];
} else {
return [[BITImageAnnotation alloc] initWithFrame:CGRectZero];
}
}
#pragma mark - Actions
- (void)discard:(id)sender {
[self.delegate annotationControllerDidCancel:self];
[self dismissModalViewControllerAnimated:YES];
}
- (void)save:(id)sender {
UIImage *image = [self extractImage];
[self.delegate annotationController:self didFinishWithImage:image];
[self dismissModalViewControllerAnimated:YES];
}
- (UIImage *)extractImage {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, YES, 0.0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:ctx];
UIImage *renderedImageOfMyself = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return renderedImageOfMyself;
}
#pragma mark - Gesture Handling
- (void)panned:(UIPanGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
self.currentAnnotation = [self annotationForCurrentMode];
[self.view 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);
}
}
-(void)tapped:(UITapGestureRecognizer *)gestureRecognizer {
}
- (void)didReceiveMemoryWarning