码迷,mamicode.com
首页 > 其他好文 > 详细

AVfoundation中焦距的设置(slider实现拉近拉远镜头) -自定义UISlider

时间:2015-02-06 16:39:43      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

首先设置一个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;

    }];


}

AVfoundation中焦距的设置(slider实现拉近拉远镜头) -自定义UISlider

标签:

原文地址:http://www.cnblogs.com/allanliu/p/4277438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!