让父控件上的 图片等view 跟着画出的路线移动
#import "aaDrawView.h"
@interface aaDrawView ()
@property (nonatomic ,retain) UIBezierPath *path;
@end
@implementation aaDrawView
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint cup = [touch locationInView:self];
UIBezierPath *path = [UIBezierPath bezierPath];
_path = path;
[path moveToPoint:cup];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint cup = [touch locationInView:self];
[_path addLineToPoint:cup];
[self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
anim.keyPath = @"position";
anim.path = _path.CGPath;
anim.duration = 2;
anim.removedOnCompletion = NO;
anim.fillMode = kCAFillModeForwards;
[[[self.subviews firstObject] layer] addAnimation:anim forKey:nil];
}
- (void)drawRect:(CGRect)rect
{
[_path stroke];
}
E928A901-2C88-41C7-8034-C58D8AE07CB5.png
053FFF89-776F-4F8C-A052-A426C54E49B8.png
D5E9D568-BAD1-45F8-8B7D-5A866EDAD701.png
6C9AD3D0-1F0B-4A76-9EF4-77190222CD15.png
网友评论