Skip to content

Commit f0800d6

Browse files
author
yuvraj
committed
Give auto-flash mode
Add Auto-Flash mode for flash functionality.
1 parent 406b6a2 commit f0800d6

File tree

7 files changed

+46
-52
lines changed

7 files changed

+46
-52
lines changed

YCameraView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Pod::Spec.new do |s|
88
s.name = "YCameraView"
9-
s.version = "1.0.1"
9+
s.version = "1.1.0"
1010

1111
s.summary = "Custom Camera Controller similar to the camera View on Instagram."
1212

YCameraViewController/YCameraViewController.m

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ - (void)viewDidLoad
5757
initializeCamera = YES;
5858
photoFromCam = YES;
5959

60+
// Set auto-flash initially
61+
self.flashToggleButton.tag = AVCaptureFlashModeAuto;
62+
6063
// Initialize Motion Manager
6164
[self initializeMotionManager];
6265
}
@@ -231,10 +234,15 @@ - (void) initializeCamera {
231234

232235
if ([backCamera hasFlash]){
233236
[backCamera lockForConfiguration:nil];
234-
if (self.flashToggleButton.selected)
237+
if (self.flashToggleButton.tag==AVCaptureFlashModeAuto){
238+
[backCamera setFlashMode:AVCaptureFlashModeAuto];
239+
}
240+
else if(self.flashToggleButton.tag==AVCaptureFlashModeOn){
235241
[backCamera setFlashMode:AVCaptureFlashModeOn];
236-
else
242+
}
243+
else{
237244
[backCamera setFlashMode:AVCaptureFlashModeOff];
245+
}
238246
[backCamera unlockForConfiguration];
239247

240248
[self.flashToggleButton setEnabled:YES];
@@ -537,55 +545,42 @@ - (IBAction)switchCamera:(UIButton *)sender { //switch cameras front and rear ca
537545

538546
- (IBAction)toogleFlash:(UIButton *)sender{
539547
if (!FrontCamera) {
540-
if (sender.selected) { // Set flash off
541-
[sender setSelected:NO];
542-
543-
NSArray *devices = [AVCaptureDevice devices];
544-
for (AVCaptureDevice *device in devices) {
545-
546-
NSLog(@"Device name: %@", [device localizedName]);
547-
548-
if ([device hasMediaType:AVMediaTypeVideo]) {
549-
550-
if ([device position] == AVCaptureDevicePositionBack) {
551-
NSLog(@"Device position : back");
552-
if ([device hasFlash]){
553-
554-
[device lockForConfiguration:nil];
555-
[device setFlashMode:AVCaptureFlashModeOff];
556-
[device unlockForConfiguration];
557-
558-
break;
559-
}
560-
}
561-
}
562-
}
548+
549+
NSArray *devices = [AVCaptureDevice devices];
550+
for (AVCaptureDevice *device in devices) {
563551

564-
}
565-
else{ // Set flash on
566-
[sender setSelected:YES];
552+
NSLog(@"Device name: %@", [device localizedName]);
567553

568-
NSArray *devices = [AVCaptureDevice devices];
569-
for (AVCaptureDevice *device in devices) {
570-
571-
NSLog(@"Device name: %@", [device localizedName]);
554+
if ([device hasMediaType:AVMediaTypeVideo]) {
572555

573-
if ([device hasMediaType:AVMediaTypeVideo]) {
574-
575-
if ([device position] == AVCaptureDevicePositionBack) {
576-
NSLog(@"Device position : back");
577-
if ([device hasFlash]){
578-
579-
[device lockForConfiguration:nil];
556+
if ([device position] == AVCaptureDevicePositionBack) {
557+
NSLog(@"Device position : back");
558+
if ([device hasFlash]){
559+
560+
[device lockForConfiguration:nil];
561+
562+
if (sender.tag==AVCaptureFlashModeAuto) { // Current flash mode is Auto, set it to On
580563
[device setFlashMode:AVCaptureFlashModeOn];
581-
[device unlockForConfiguration];
582-
583-
break;
564+
sender.tag = AVCaptureFlashModeOn;
565+
[sender setImage:[UIImage imageNamed:@"flash"] forState:UIControlStateNormal];
584566
}
567+
else if (sender.tag==AVCaptureFlashModeOn){ // Current flash mode is On, set it to Off
568+
[device setFlashMode:AVCaptureFlashModeOff];
569+
sender.tag = AVCaptureFlashModeOff;
570+
[sender setImage:[UIImage imageNamed:@"flash-off"] forState:UIControlStateNormal];
571+
}
572+
else{ // Current flash mode is Off, set it to Auto
573+
[device setFlashMode:AVCaptureFlashModeAuto];
574+
sender.tag = AVCaptureFlashModeAuto;
575+
[sender setImage:[UIImage imageNamed:@"flash-auto"] forState:UIControlStateNormal];
576+
}
577+
578+
[device unlockForConfiguration];
579+
580+
break;
585581
}
586582
}
587583
}
588-
589584
}
590585
}
591586
}

YCameraViewController/YCameraViewController.xib

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
33
<dependencies>
4-
<deployment identifier="iOS"/>
54
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
65
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
76
</dependencies>
@@ -254,7 +253,7 @@
254253
<action selector="switchCamera:" destination="-1" eventType="touchUpInside" id="r67-BA-1il"/>
255254
</connections>
256255
</button>
257-
<button opaque="NO" contentMode="scaleToFill" selected="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NJj-5f-Bzl">
256+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NJj-5f-Bzl">
258257
<rect key="frame" x="0.0" y="0.0" width="44" height="44"/>
259258
<constraints>
260259
<constraint firstAttribute="width" constant="44" id="1dr-ep-eys"/>
@@ -263,7 +262,7 @@
263262
<constraint firstAttribute="width" secondItem="NJj-5f-Bzl" secondAttribute="height" multiplier="1:1" id="pPC-51-XVe"/>
264263
</constraints>
265264
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
266-
<state key="normal" image="flash-off.png">
265+
<state key="normal" image="flash-auto.png">
267266
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
268267
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
269268
</state>
@@ -678,7 +677,7 @@
678677
</view>
679678
</objects>
680679
<resources>
681-
<image name="flash-off.png" width="25" height="25"/>
680+
<image name="flash-auto.png" width="25" height="25"/>
682681
<image name="flash.png" width="25" height="25"/>
683682
<image name="front-camera.png" width="47" height="23"/>
684683
<image name="grid-icon.png" width="25" height="25"/>

YCameraViewDemo/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source 'https://github.com/CocoaPods/Specs.git'
22
platform :ios, '7.0'
33
xcodeproj 'YCameraViewDemo.xcodeproj'
4-
pod 'YCameraView', '1.0.0'
4+
pod 'YCameraView', '1.1.0'

YCameraViewDemo/YCameraViewDemo.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
isa = PBXProject;
191191
attributes = {
192192
LastUpgradeCheck = 0620;
193-
ORGANIZATIONNAME = rapidops;
193+
ORGANIZATIONNAME = yuvrajsinh;
194194
TargetAttributes = {
195195
8B153F441B66498C00DF40C2 = {
196196
CreatedOnToolsVersion = 6.2;

YCameraViewDemo/YCameraViewDemo/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
10-
<string>com.rapidops.$(PRODUCT_NAME:rfc1034identifier)</string>
10+
<string>com.company.$(PRODUCT_NAME:rfc1034identifier)</string>
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>

0 commit comments

Comments
 (0)