The key is not to update the image, but simply draw an arrow on top of the image. Then replace the arrow with another when touchesMoved
appears.
For example, I can use QuartzCore.framework by adding it to your target βLink Binary With Librariesβ and adding the following line to the top of your .m:
#import <QuartzCore/QuartzCore.h>
Then you can define a new ivar for your CAShapeLayer
:
CAShapeLayer *shapeLayer;
Finally, upgrade your touchesMoved
to the following value:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ArrowDraw==YES){ if ([[event allTouches]count]==1) { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:FullImageView]; if (!shapeLayer) { shapeLayer = [CAShapeLayer layer]; shapeLayer.lineWidth = 1; shapeLayer.strokeColor = [[UIColor blackColor] CGColor]; shapeLayer.fillColor = [[UIColor clearColor] CGColor]; [FullImageView.layer addSublayer:shapeLayer]; } UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:firstPoint]; [path addLineToPoint:currentPoint]; shapeLayer.path = [path CGPath]; } } }
You can modify this UIBezierPath
to include an arrow if you need it, for example:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ArrowDraw==YES){ if ([[event allTouches]count]==1) { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:FullImageView]; if (!shapeLayer) { [self createShapeLayer]; } shapeLayer.path = [[self arrowPathFrom:firstPoint to:currentPoint arrowheadSize:10.0] CGPath]; } } } - (void)createShapeLayer { shapeLayer = [CAShapeLayer layer]; shapeLayer.lineWidth = 1; shapeLayer.strokeColor = [[UIColor blackColor] CGColor]; shapeLayer.fillColor = [[UIColor clearColor] CGColor]; [FullImageView.layer addSublayer:shapeLayer]; } - (UIBezierPath *)arrowPathFrom:(CGPoint)start to:(CGPoint)end arrowheadSize:(CGFloat)arrowheadSize { UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:start]; [path addLineToPoint:end];
Rob source share