Showing
1 changed file
with
23 additions
and
12 deletions
@@ -311,7 +311,8 @@ | @@ -311,7 +311,8 @@ | ||
311 | _torch_switch= NO; | 311 | _torch_switch= NO; |
312 | _btnTorch = [UIButton buttonWithType:UIButtonTypeCustom]; | 312 | _btnTorch = [UIButton buttonWithType:UIButtonTypeCustom]; |
313 | _btnTorch.frame = CGRectMake(size.width - 4*icon_gap - 4*icon_size, size.height - 10 - icon_size, icon_size, icon_size); | 313 | _btnTorch.frame = CGRectMake(size.width - 4*icon_gap - 4*icon_size, size.height - 10 - icon_size, icon_size, icon_size); |
314 | - [_btnTorch setImage:[UIImage imageNamed:@"flash_on"] forState:UIControlStateNormal]; | 314 | + [_btnTorch setImage:[UIImage imageNamed:@"flash_off"] forState:UIControlStateNormal]; |
315 | + [_btnTorch setImage:[UIImage imageNamed:@"flash_on"] forState:UIControlStateSelected]; | ||
315 | [_btnTorch addTarget:self action:@selector(clickTorch:) forControlEvents:UIControlEventTouchUpInside]; | 316 | [_btnTorch addTarget:self action:@selector(clickTorch:) forControlEvents:UIControlEventTouchUpInside]; |
316 | [self.view addSubview:_btnTorch]; | 317 | [self.view addSubview:_btnTorch]; |
317 | 318 | ||
@@ -614,18 +615,28 @@ | @@ -614,18 +615,28 @@ | ||
614 | -(void) clickTorch:(UIButton*) btn | 615 | -(void) clickTorch:(UIButton*) btn |
615 | { | 616 | { |
616 | if (_txLivePublisher) { | 617 | if (_txLivePublisher) { |
618 | + btn.selected = !btn.selected; | ||
617 | _torch_switch = !_torch_switch; | 619 | _torch_switch = !_torch_switch; |
618 | - if (![_txLivePublisher toggleTorch:_torch_switch]) { | ||
619 | - _torch_switch = !_torch_switch; | ||
620 | - [self toastTip:@"闪光灯启动失败"]; | ||
621 | - } | ||
622 | - | ||
623 | - if (_torch_switch == YES) { | ||
624 | - [_btnTorch setImage:[UIImage imageNamed:@"flash_off"] forState:UIControlStateNormal]; | ||
625 | - } | ||
626 | - else | ||
627 | - { | ||
628 | - [_btnTorch setImage:[UIImage imageNamed:@"flash_on"] forState:UIControlStateNormal]; | 620 | +// if (![_txLivePublisher toggleTorch:_torch_switch]) { |
621 | +// _torch_switch = !_torch_switch; | ||
622 | +// [self toastTip:@"闪光灯启动失败"]; | ||
623 | +// } | ||
624 | + AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; | ||
625 | + | ||
626 | + if (_torch_switch) { | ||
627 | + if ([device hasTorch]) { | ||
628 | + [device lockForConfiguration:nil]; | ||
629 | + [device setTorchMode: AVCaptureTorchModeOn]; | ||
630 | + [device unlockForConfiguration]; | ||
631 | + }else { | ||
632 | + [self toastTip:@"闪光灯启动失败"]; | ||
633 | + } | ||
634 | + }else { | ||
635 | + if ([device hasTorch]) { | ||
636 | + [device lockForConfiguration:nil]; | ||
637 | + [device setTorchMode: AVCaptureTorchModeOff]; | ||
638 | + [device unlockForConfiguration]; | ||
639 | + } | ||
629 | } | 640 | } |
630 | } | 641 | } |
631 | } | 642 | } |
-
Please register or login to post a comment