打开手电筒照明的思路:初始化相机设备 -> 点击按钮 -> 改变照明状态 -> 根据状态打开或关闭手电筒
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property (nonatomic, strong) AVCaptureDevice *device;//捕获设备
@end
@implementation ViewController
{
BOOL device_open;//判断照明状态
UIButton *scanBtn;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//创建按钮
[self creatControl];
}
- (void)creatControl {
//初始化相机设备
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
//照明按钮
scanBtn = [UIButton buttonWithType:UIButtonTypeSystem];
scanBtn.frame = CGRectMake(100, 100, 100, 44);
[scanBtn setTitle:@"打开照明" forState:UIControlStateNormal];
[scanBtn addTarget:self action:@selector(scanBtnOnClick) forControlEve