- (instancetype)initWithFrame:(CGRect)frame{
self.userInteractionEnabled = YES;
if(self = [super initWithFrame:frame]){
UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(gestureRecognizer:)];
[self addGestureRecognizer:gestureRecognizer];
}
return self;
}
-(void)gestureRecognizer:(UIPanGestureRecognizer*)pan{
CGFloat w = 30;
CGPoint point = [pan locationInView:self];
CGFloat x = point.x - w * 0.5;
CGFloat y = point.y - w * 0.5;
CGRect rect = CGRectMake(x, y, w, w);
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.layer renderInContext:ctx];
CGContextClearRect(ctx, rect);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.image = newImage;
}
网友评论