` -(void)setupFilter{
//创建摄像头视图 GPUImageView *filterView = [[GPUImageView alloc]initWithFrame:self.view.bounds]; UITapGestureRecognizer tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapOnVideoView:)]; [filterView addGestureRecognizer:tap]; } //聚焦 -(void)tapOnVideoView:(UITapGestureRecognizer)recognizer{
CGPoint point = [recognizer locationInView:recognizer.view];
UIView *preView = recognizer.view;
CGPoint focusPoint = CGPointMake(point.x/preView.width, point.y/preView.height);
NSError *error;
if([videoCamera.inputCamera lockForConfiguration:&error]){
//对焦模式和对焦点,设定前一定要判断该模式是否支持,如果支持就先设定位置,然后再设定模式,单独设定位置是没有用的。曝光设置跟这里一样的原理
if([videoCamera.inputCamera isFocusModeSupported:AVCaptureFocusModeAutoFocus]){
[videoCamera.inputCamera setFocusPointOfInterest:focusPoint];
[videoCamera.inputCamera setFocusMode:AVCaptureFocusModeAutoFocus];
}
//曝光模式和曝光点
if([videoCamera.inputCamera isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
[videoCamera.inputCamera setExposurePointOfInterest:focusPoint];
[videoCamera.inputCamera setExposureMode:AVCaptureExposureModeAutoExpose];
}
//当你lockForConfiguration后,完成设置后记住一定要unlock
[videoCamera.inputCamera unlockForConfiguration];
//设置对焦动画
_focusPoint.center = point;
_focusPoint.hidden = NO;
[UIView animateWithDuration:0.3f animations:^{
_focusPoint.transform = CGAffineTransformMakeScale(1.25, 1.25);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5f animations:^{
_focusPoint.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
_focusPoint.hidden = YES;
}];
}];
}
}
` 其实实现这个功能还是很简单的,关于设置的顺序,可以点击相应的属性进去看看,文档里说的很清楚,建议大家还是要仔细看看,自己亲身体会一下。