开灯关灯
if
(sender.
selected
) {
[sender setTitle : @" 关灯 " forState : UIControlStateNormal ];
[device setTorchMode : AVCaptureTorchModeOn ];
[device setFlashMode : AVCaptureFlashModeOn ];
} else {
[sender setTitle : @" 开灯 " forState : UIControlStateNormal ];
[device setTorchMode : AVCaptureTorchModeOff ];
[device setFlashMode : AVCaptureFlashModeOff ];
}
[sender setTitle : @" 关灯 " forState : UIControlStateNormal ];
[device setTorchMode : AVCaptureTorchModeOn ];
[device setFlashMode : AVCaptureFlashModeOn ];
} else {
[sender setTitle : @" 开灯 " forState : UIControlStateNormal ];
[device setTorchMode : AVCaptureTorchModeOff ];
[device setFlashMode : AVCaptureFlashModeOff ];
}
[device unlockForConfiguration];
开机动画,或者再window上写,不过需要纯代码创建window
static
dispatch_once_t
onceToken;
dispatch_once
(&onceToken, ^{
// 开机启动动画
UIImageView *splashView = [[ UIImageView alloc ] initWithFrame : CGRectMake ( 0 , 0 , ScreenWidth , ScreenHeight )];
// 将图片添加到 UIImageView 对象中
splashView. image =[ UIImage imageNamed : @"bg_night_snow" ];
[ self . view addSubview :splashView];
[ self . view bringSubviewToFront :splashView];
[ UIView animateWithDuration : 4.f animations :^{
self . navigationController . navigationBar . hidden = YES ;
splashView. frame = CGRectMake (- 55 / 375. * ScreenWidth , - 100. / 667 * ScreenHeight , ScreenWidth + 100 , ScreenHeight + 100 + 100 );
} completion :^( BOOL finished) {
splashView. hidden = YES ;
self . navigationController . navigationBar . hidden = NO ;
// 开机启动动画
UIImageView *splashView = [[ UIImageView alloc ] initWithFrame : CGRectMake ( 0 , 0 , ScreenWidth , ScreenHeight )];
// 将图片添加到 UIImageView 对象中
splashView. image =[ UIImage imageNamed : @"bg_night_snow" ];
[ self . view addSubview :splashView];
[ self . view bringSubviewToFront :splashView];
[ UIView animateWithDuration : 4.f animations :^{
self . navigationController . navigationBar . hidden = YES ;
splashView. frame = CGRectMake (- 55 / 375. * ScreenWidth , - 100. / 667 * ScreenHeight , ScreenWidth + 100 , ScreenHeight + 100 + 100 );
} completion :^( BOOL finished) {
splashView. hidden = YES ;
self . navigationController . navigationBar . hidden = NO ;
}];
});