diff --git a/YCameraView.podspec b/YCameraView.podspec index a8758bc..d48e6f3 100644 --- a/YCameraView.podspec +++ b/YCameraView.podspec @@ -6,7 +6,7 @@ Pod::Spec.new do |s| s.name = "YCameraView" - s.version = "1.0.1" + s.version = "1.1.0" s.summary = "Custom Camera Controller similar to the camera View on Instagram." diff --git a/YCameraViewController/YCameraViewController.m b/YCameraViewController/YCameraViewController.m index 2277117..0c08470 100644 --- a/YCameraViewController/YCameraViewController.m +++ b/YCameraViewController/YCameraViewController.m @@ -57,6 +57,9 @@ - (void)viewDidLoad initializeCamera = YES; photoFromCam = YES; + // Set auto-flash initially + self.flashToggleButton.tag = AVCaptureFlashModeAuto; + // Initialize Motion Manager [self initializeMotionManager]; } @@ -231,10 +234,15 @@ - (void) initializeCamera { if ([backCamera hasFlash]){ [backCamera lockForConfiguration:nil]; - if (self.flashToggleButton.selected) + if (self.flashToggleButton.tag==AVCaptureFlashModeAuto){ + [backCamera setFlashMode:AVCaptureFlashModeAuto]; + } + else if(self.flashToggleButton.tag==AVCaptureFlashModeOn){ [backCamera setFlashMode:AVCaptureFlashModeOn]; - else + } + else{ [backCamera setFlashMode:AVCaptureFlashModeOff]; + } [backCamera unlockForConfiguration]; [self.flashToggleButton setEnabled:YES]; @@ -537,55 +545,42 @@ - (IBAction)switchCamera:(UIButton *)sender { //switch cameras front and rear ca - (IBAction)toogleFlash:(UIButton *)sender{ if (!FrontCamera) { - if (sender.selected) { // Set flash off - [sender setSelected:NO]; - - NSArray *devices = [AVCaptureDevice devices]; - for (AVCaptureDevice *device in devices) { - - NSLog(@"Device name: %@", [device localizedName]); - - if ([device hasMediaType:AVMediaTypeVideo]) { - - if ([device position] == AVCaptureDevicePositionBack) { - NSLog(@"Device position : back"); - if ([device hasFlash]){ - - [device lockForConfiguration:nil]; - [device setFlashMode:AVCaptureFlashModeOff]; - [device unlockForConfiguration]; - - break; - } - } - } - } + + NSArray *devices = [AVCaptureDevice devices]; + for (AVCaptureDevice *device in devices) { - } - else{ // Set flash on - [sender setSelected:YES]; + NSLog(@"Device name: %@", [device localizedName]); - NSArray *devices = [AVCaptureDevice devices]; - for (AVCaptureDevice *device in devices) { - - NSLog(@"Device name: %@", [device localizedName]); + if ([device hasMediaType:AVMediaTypeVideo]) { - if ([device hasMediaType:AVMediaTypeVideo]) { - - if ([device position] == AVCaptureDevicePositionBack) { - NSLog(@"Device position : back"); - if ([device hasFlash]){ - - [device lockForConfiguration:nil]; + if ([device position] == AVCaptureDevicePositionBack) { + NSLog(@"Device position : back"); + if ([device hasFlash]){ + + [device lockForConfiguration:nil]; + + if (sender.tag==AVCaptureFlashModeAuto) { // Current flash mode is Auto, set it to On [device setFlashMode:AVCaptureFlashModeOn]; - [device unlockForConfiguration]; - - break; + sender.tag = AVCaptureFlashModeOn; + [sender setImage:[UIImage imageNamed:@"flash"] forState:UIControlStateNormal]; } + else if (sender.tag==AVCaptureFlashModeOn){ // Current flash mode is On, set it to Off + [device setFlashMode:AVCaptureFlashModeOff]; + sender.tag = AVCaptureFlashModeOff; + [sender setImage:[UIImage imageNamed:@"flash-off"] forState:UIControlStateNormal]; + } + else{ // Current flash mode is Off, set it to Auto + [device setFlashMode:AVCaptureFlashModeAuto]; + sender.tag = AVCaptureFlashModeAuto; + [sender setImage:[UIImage imageNamed:@"flash-auto"] forState:UIControlStateNormal]; + } + + [device unlockForConfiguration]; + + break; } } } - } } } diff --git a/YCameraViewController/YCameraViewController.xib b/YCameraViewController/YCameraViewController.xib index 0029118..b4800a5 100755 --- a/YCameraViewController/YCameraViewController.xib +++ b/YCameraViewController/YCameraViewController.xib @@ -1,7 +1,6 @@ - + - @@ -254,7 +253,7 @@ -