AVfoundation中焦距的设置(slider实现拉近拉远镜头) -自定义UISlider
首先设置一个slider
UISlider focusSlider = [[UISlideralloc]initWithFrame:CGRectMake(60,_bottomView.frame.origin.y-60,200,20)];
[focusSlideraddTarget:selfaction:@selector(AdjustFocusAction:)forControlEvents:UIControlEventValueChanged];
[focusSlidersetThumbImage:[UIImageimageNamed:@"camera_view_slider_take_gray.png"]forState:UIControlStateNormal];
[focusSlidersetMinimumTrackImage:[UIImageimageNamed:@"camera_view_sliderbar_gray.png"]forState:UIControlStateNormal];
[focusSlidersetMaximumTrackImage:[UIImageimageNamed:@"camera_view_sliderbar_gray.png"]forState:UIControlStateNormal];
[focusSlidersetBackgroundColor:[UIColorclearColor]];
[focusSlidersetMaximumValue:1];
[focusSlidersetMinimumValue:0];
[focusSlider setValue:0.0];
[self.viewaddSubview:focusSlider];
以下做一下有关相机的设置(只写出来了其中一部分,并非全部)
preview = [AVCaptureVideoPreviewLayerlayerWithSession:self.session];
self.preview.frame =CGRectMake(0,0, self.cameraView.frame.size.width,self.cameraView.frame.size.height);
[self.previewsetPosition:CGPointMake(CGRectGetMidX(self.cameraView.bounds),CGRectGetMidY(self.cameraView.bounds))];
self.preview.videoGravity =AVLayerVideoGravityResize;
[self.cameraView.layeraddSublayer:self.preview];
captureOutput = (AVCaptureStillImageOutput*)[self.session.outputsobjectAtIndex:0];
focusConnection =[captureOutput connectionWithMediaType:AVMediaTypeVideo];
调节焦距
-(void)AdjustFocusAction:(id)sender
{
[UIViewanimateWithDuration:0.025animations:^{
[self.previewsetAffineTransform:CGAffineTransformMakeScale([(UISlider *)sendervalue]+1, [(UISlider *)sendervalue]+1)];
focusConnection.videoScaleAndCropFactor = [(UISlider *)sendervalue]+1;
}];
}