Skip to content

Commit

Permalink
Give auto-flash mode
Browse files Browse the repository at this point in the history
Add Auto-Flash mode for flash functionality.
  • Loading branch information
yuvraj committed Aug 4, 2015
1 parent 406b6a2 commit f0800d6
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 52 deletions.
2 changes: 1 addition & 1 deletion YCameraView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down
81 changes: 38 additions & 43 deletions YCameraViewController/YCameraViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ - (void)viewDidLoad
initializeCamera = YES;
photoFromCam = YES;

// Set auto-flash initially
self.flashToggleButton.tag = AVCaptureFlashModeAuto;

// Initialize Motion Manager
[self initializeMotionManager];
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
}
}

}
}
}
Expand Down
9 changes: 4 additions & 5 deletions YCameraViewController/YCameraViewController.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6751" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
Expand Down Expand Up @@ -254,7 +253,7 @@
<action selector="switchCamera:" destination="-1" eventType="touchUpInside" id="r67-BA-1il"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" selected="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NJj-5f-Bzl">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NJj-5f-Bzl">
<rect key="frame" x="0.0" y="0.0" width="44" height="44"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="1dr-ep-eys"/>
Expand All @@ -263,7 +262,7 @@
<constraint firstAttribute="width" secondItem="NJj-5f-Bzl" secondAttribute="height" multiplier="1:1" id="pPC-51-XVe"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" image="flash-off.png">
<state key="normal" image="flash-auto.png">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
Expand Down Expand Up @@ -678,7 +677,7 @@
</view>
</objects>
<resources>
<image name="flash-off.png" width="25" height="25"/>
<image name="flash-auto.png" width="25" height="25"/>
<image name="flash.png" width="25" height="25"/>
<image name="front-camera.png" width="47" height="23"/>
<image name="grid-icon.png" width="25" height="25"/>
Expand Down
2 changes: 1 addition & 1 deletion YCameraViewDemo/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
xcodeproj 'YCameraViewDemo.xcodeproj'
pod 'YCameraView', '1.0.0'
pod 'YCameraView', '1.1.0'
2 changes: 1 addition & 1 deletion YCameraViewDemo/YCameraViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0620;
ORGANIZATIONNAME = rapidops;
ORGANIZATIONNAME = yuvrajsinh;
TargetAttributes = {
8B153F441B66498C00DF40C2 = {
CreatedOnToolsVersion = 6.2;
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion YCameraViewDemo/YCameraViewDemo/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.rapidops.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>com.company.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down

0 comments on commit f0800d6

Please sign in to comment.