Iphone 如何重置或清除与CGContext关联的剪辑掩码?
我正在绘制CGContext并使用基于CGImageRef的掩码:Iphone 如何重置或清除与CGContext关联的剪辑掩码?,iphone,core-graphics,cgcontext,Iphone,Core Graphics,Cgcontext,我正在绘制CGContext并使用基于CGImageRef的掩码: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClipToMask(context, rect, _firstMaskImageRef); CGContextSetFillColorWithColor(context, color); CGContextFillRect(context, rect); 我有第二个面具,然后我想切换到: CGCon
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, rect, _firstMaskImageRef);
CGContextSetFillColorWithColor(context, color);
CGContextFillRect(context, rect);
我有第二个面具,然后我想切换到:
CGContextClipToMask(context, rect, _secondMaskImageRef);
CGContextSetFillColorWithColor(context, color); // color has changed FWIW
CGContextFillRect(context, rect); // as has rect
但是,这会将两个遮罩相交,而不是替换第一个遮罩
如何(如果可以)清除或重置CGContext的剪裁遮罩?您可以在设置剪裁遮罩之前保存图形状态,然后再重置,如下所示:
CGContextSaveGState (context);
...Set your first clipping mask, fill it, etc.
CGContextRestoreGState (context);
...Do other stuff
更高版本的Swift(3+?)使用以下语法:
context.saveGState()
//设置剪辑遮罩等。
context.restoreGState()
//一切都恢复正常了
要重置剪裁遮罩,请使用:
CGContextResetClip(context);