ZhengYanFeng1989的博客

懂得太少,表现太多;才华太少,锋芒太多,很浅薄,一眼就能被看穿. 沉下来,打根基,让别人不会觉得你烦!...

iOS 闪光灯的打开和关闭
//
//  ViewController.m
//  Flash
//
//  Created by fe on 2017/1/3.
//  Copyright © 2017年 fe. All rights reserved.
//

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>//调用闪光灯需要导入该框架
@interface ViewController ()

- (IBAction)openFlash:(UIButton *)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)openFlash:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    if (sender.isSelected == YES) { //打开闪光灯
        AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        NSError *error = nil;
        
        if ([captureDevice hasTorch]) {
            BOOL locked = [captureDevice lockForConfiguration:&error];
            if (locked) {
                captureDevice.torchMode = AVCaptureTorchModeOn;
                [captureDevice unlockForConfiguration];
            }
        }
    }else{//关闭闪光灯
        AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        if ([device hasTorch]) {
            [device lockForConfiguration:nil];
            [device setTorchMode: AVCaptureTorchModeOff];
            [device unlockForConfiguration];
        }
    }
   

    
}
- (IBAction)closeFlash:(UIButton *)sender {
    
}

@end

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZhengYanFeng1989/article/details/53994865
个人分类: iOS开发
上一篇java 基础 使用 Math 类操作数据
下一篇java 基础 标记和重载
想对作者说点什么? 我来说一句

iOS进阶开发-iOS性能优化

-

学院

1970年01月01日 08:00

ios 闪光灯操作

2013年12月10日 36KB 下载

没有更多推荐了,返回首页

不良信息举报

iOS 闪光灯的打开和关闭

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭