**取景器制作步骤**:
1、创建一个UIImagePickerController,使用摄像头作为来源;
2、必须在显示图像选取器之前,加上一个让用户拍照的方法;
3、用一个Uiview作为叠加层,你可以像对待任何其他UIView一样来处理这个叠加层,你可以加上动画,加上任意的子视图等等。
下面的代码演示了一个简单的取景器
- (IBAction)showCustomCamera:(id)sender
{
//创建UIImagePickerController
picker = [[UIImagePickerController alloc]init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;//选取摄像头作为来源
[picker setDelegate:self];
picker.showsCameraControls = YES;//是否禁用摄像头空件
//创建叠加层
UIView *overLayView = [[UIView alloc]initWithFrame:self.view.bounds];
//取景器的背景图片,该图片中间挖掉了一块变成透明,用来显示摄像头获取的图片;
UIImage *overLayImag = [UIImage imageNamed:@"TR.png"];
UIImageView *bgImageView = [[UIImageView alloc]initWithImage:overLayImag];
[overLayView addSubview:bgImageView];
//将视图设置为摄像头的叠加层
picker.cameraOverlayView = overLayView;
//显示选取器
[self presentModalViewController:picker animated:YES];
}
- (void)takePhoto:(id)sender
{
[picker takePicture];//他将会自动调用代理方法完成照片的拍摄;
}