Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 擦除UIImageView的矩形_Iphone_Objective C_Ios_Ipad_Uiimageview - Fatal编程技术网

Iphone 擦除UIImageView的矩形

Iphone 擦除UIImageView的矩形,iphone,objective-c,ios,ipad,uiimageview,Iphone,Objective C,Ios,Ipad,Uiimageview,我想知道,如何擦除UIImageView的自定义rect(例如,使用IB中的UIView或其他内容),以便显示位于下方的另一个UIImageView 我没有在论坛上用一些回应来做到这一点 可能不是最好的解决方案,但您可以用另一种方法,将矩形周围的4个部分分开,然后在没有内部矩形的情况下将它们合并。只要要裁剪出rect,就可以重复此操作。无法清除UIImageView本身,因为这只是绘制UIImage。因此,您必须删除UIImage中的rect。创建位图上下文,将图像绘制到其中。用CGCont

我想知道,如何擦除
UIImageView
的自定义rect(例如,使用
IB
中的
UIView
或其他内容),以便显示位于下方的另一个
UIImageView



我没有在论坛上用一些回应来做到这一点

可能不是最好的解决方案,但您可以用另一种方法,将矩形周围的4个部分分开,然后在没有内部矩形的情况下将它们合并。只要要裁剪出rect,就可以重复此操作。

无法清除UIImageView本身,因为这只是绘制UIImage。因此,您必须删除UIImage中的rect。创建位图上下文,将图像绘制到其中。用CGContextClearRect擦除要“看穿”的部分。从位图上下文创建新图像时。

这将清除图像中的rect:

- (UIImage *)clearRect:(CGRect)rect inImage:(UIImage *)image {

    if (UIGraphicsBeginImageContextWithOptions != NULL)
        UIGraphicsBeginImageContextWithOptions([image size], NO, 0.0);
    else
        UIGraphicsBeginImageContext([image size]);

    CGContextRef context = UIGraphicsGetCurrentContext();

    [image drawInRect:CGRectMake(0.0, 0.0, [image size].width, [image size].height)];
    CGContextClearRect(context, rect);

    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return result;
}
在将图像指定给图像视图之前,只需加载图像并清除矩形即可:

UIImage *image = [UIImage imageNamed:@"Image.png"];
UIImage *maskedImage = [self clearRect:CGRectMake(10.0, 10.0, 50.0, 50.0) inImage:image];
[imageView setImage:maskedImage];

你试过遮罩图像吗?示例:这与我尝试做的事情并不完全相同。为什么不只是将图像引入CoreGraphics并使用
CGContextClearRect
之类的工具?你能发布一些代码看看如何实现它吗?事实上,我找到了一种QuarzCore或CoreGraphic方法。但是是的,它可以完成这项工作。