图片擦除的是现实思路

2016-08-14  本文已影响24人  我勒个去的
- (void)pan:(UIPanGestureRecognizer *)pan{

    //获取当前手指所在的点
    CGPoint curP = [pan locationInView:self.imageV];
    CGFloat rectWH = 50;
    CGFloat x = curP.x - rectWH * 0.5;
    CGFloat y = curP.y - rectWH * 0.5;
    CGRect rect =   CGRectMake(x, y, rectWH, rectWH);
    
    //开启一个图片上下文.
    UIGraphicsBeginImageContextWithOptions(self.imageV.bounds.size, NO, 0);
    
    //获取当前的上下文.
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    //把UImageViwe上面的图片给绘制到上下文.
    [self.imageV.layer renderInContext:ctx];
    
    //确定擦除区域
    CGContextClearRect(ctx, rect);
    
    //生成一张新图片
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    //把上下文给关闭
    UIGraphicsEndImageContext();
    //给原来图片重新赋值
    self.imageV.image = newImage;
    
上一篇 下一篇

猜你喜欢

热点阅读