或者,您可以像这样覆盖cameraOverlayView的- (void)drawRect:(CGRect)rect
方法(未经测试):
// Request draw context
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw background
CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f);
CGContextFillRect(context, rect);
// Cut hole
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextFillRect(context, CGRectMake(40, 40, 100, 100);
我在我的Faces应用程序中做过类似的事情(http://faces.pixelshed.net/)。如果其中某个步骤不清楚,请随时发表评论。
cameraOverlayView
是图片选择器控制器的一个属性,被简单地公开为一个UIView
:https://developer.apple.com/library/ios/documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/occ/instp/UIImagePickerController/cameraOverlayView - BoltClock