mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 19:09:56 +00:00
+ Added #63 (Moving drawn elements.)
This commit is contained in:
parent
474026f04e
commit
b33ee9a61f
@ -19,11 +19,15 @@
|
|||||||
@property (nonatomic, strong) NSMutableArray *objects;
|
@property (nonatomic, strong) NSMutableArray *objects;
|
||||||
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
|
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
|
||||||
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
|
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
|
||||||
|
@property (nonatomic, strong) UIPinchGestureRecognizer *pinchRecognizer;
|
||||||
|
|
||||||
@property (nonatomic) CGFloat scaleFactor;
|
@property (nonatomic) CGFloat scaleFactor;
|
||||||
|
|
||||||
@property (nonatomic) CGPoint panStart;
|
@property (nonatomic) CGPoint panStart;
|
||||||
@property (nonatomic,strong) BITImageAnnotation *currentAnnotation;
|
@property (nonatomic,strong) BITImageAnnotation *currentAnnotation;
|
||||||
|
|
||||||
|
@property (nonatomic) BOOL isDrawing;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation BITImageAnnotationViewController
|
@implementation BITImageAnnotationViewController
|
||||||
@ -138,17 +142,47 @@
|
|||||||
#pragma mark - Gesture Handling
|
#pragma mark - Gesture Handling
|
||||||
|
|
||||||
- (void)panned:(UIPanGestureRecognizer *)gestureRecognizer {
|
- (void)panned:(UIPanGestureRecognizer *)gestureRecognizer {
|
||||||
|
if ([self.editingControls selectedSegmentIndex] != UISegmentedControlNoSegment || self.isDrawing ){
|
||||||
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
|
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
|
||||||
self.currentAnnotation = [self annotationForCurrentMode];
|
self.currentAnnotation = [self annotationForCurrentMode];
|
||||||
[self.objects addObject:self.currentAnnotation];
|
[self.objects addObject:self.currentAnnotation];
|
||||||
self.currentAnnotation.sourceImage = self.image;
|
self.currentAnnotation.sourceImage = self.image;
|
||||||
[self.imageView insertSubview:self.currentAnnotation aboveSubview:self.imageView];
|
[self.imageView insertSubview:self.currentAnnotation aboveSubview:self.imageView];
|
||||||
self.panStart = [gestureRecognizer locationInView:self.imageView];
|
self.panStart = [gestureRecognizer locationInView:self.imageView];
|
||||||
|
|
||||||
|
[self.editingControls setSelectedSegmentIndex:UISegmentedControlNoSegment];
|
||||||
|
self.isDrawing = YES;
|
||||||
|
|
||||||
} else if (gestureRecognizer.state == UIGestureRecognizerStateChanged){
|
} else if (gestureRecognizer.state == UIGestureRecognizerStateChanged){
|
||||||
CGPoint bla = [gestureRecognizer locationInView:self.imageView];
|
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.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.movedDelta = CGSizeMake(bla.x - self.panStart.x, bla.y - self.panStart.y);
|
||||||
self.currentAnnotation.imageFrame = [self.view convertRect:self.imageView.frame toView:self.currentAnnotation];
|
self.currentAnnotation.imageFrame = [self.view convertRect:self.imageView.frame toView:self.currentAnnotation];
|
||||||
|
} else {
|
||||||
|
self.currentAnnotation = nil;
|
||||||
|
self.isDrawing = NO;
|
||||||
|
}
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
} else if (gestureRecognizer.state == UIGestureRecognizerStateChanged && self.currentAnnotation){
|
||||||
|
CGPoint delta = [gestureRecognizer translationInView:self.view];
|
||||||
|
|
||||||
|
CGRect annotationFrame = self.currentAnnotation.frame;
|
||||||
|
annotationFrame.origin.x += delta.x;
|
||||||
|
annotationFrame.origin.y += delta.y;
|
||||||
|
self.currentAnnotation.frame = annotationFrame;
|
||||||
|
|
||||||
|
[gestureRecognizer setTranslation:CGPointZero inView:self.view];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
self.currentAnnotation = nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user