Skip to content

Commit 141eb0b

Browse files
Sachin KesirajuSachin Kesiraju
authored andcommitted
Added camera view.
1 parent 85b8300 commit 141eb0b

File tree

4 files changed

+148
-2
lines changed

4 files changed

+148
-2
lines changed

SwiftExample.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
031A8D94193DCBE900F4A6D2 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031A8D93193DCBE900F4A6D2 /* TableViewController.swift */; };
1616
031A8D9A193DDD4100F4A6D2 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 031A8D99193DDD4100F4A6D2 /* WebViewController.swift */; };
1717
0356839119498B730039E42D /* MapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0356839019498B730039E42D /* MapViewController.swift */; };
18+
03B0EEB119595EF00048D16D /* CameraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03B0EEB019595EF00048D16D /* CameraViewController.swift */; };
19+
03C94697195AC0C70055D2FC /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03C94696195AC0C70055D2FC /* MobileCoreServices.framework */; };
1820
/* End PBXBuildFile section */
1921

2022
/* Begin PBXContainerItemProxy section */
@@ -40,13 +42,16 @@
4042
031A8D93193DCBE900F4A6D2 /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = "<group>"; };
4143
031A8D99193DDD4100F4A6D2 /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
4244
0356839019498B730039E42D /* MapViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapViewController.swift; sourceTree = "<group>"; };
45+
03B0EEB019595EF00048D16D /* CameraViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CameraViewController.swift; sourceTree = "<group>"; };
46+
03C94696195AC0C70055D2FC /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; };
4347
/* End PBXFileReference section */
4448

4549
/* Begin PBXFrameworksBuildPhase section */
4650
031A8D6E193DB57D00F4A6D2 /* Frameworks */ = {
4751
isa = PBXFrameworksBuildPhase;
4852
buildActionMask = 2147483647;
4953
files = (
54+
03C94697195AC0C70055D2FC /* MobileCoreServices.framework in Frameworks */,
5055
);
5156
runOnlyForDeploymentPostprocessing = 0;
5257
};
@@ -63,6 +68,7 @@
6368
031A8D68193DB57D00F4A6D2 = {
6469
isa = PBXGroup;
6570
children = (
71+
03C94696195AC0C70055D2FC /* MobileCoreServices.framework */,
6672
031A8D73193DB57D00F4A6D2 /* SwiftExample */,
6773
031A8D86193DB57D00F4A6D2 /* SwiftExampleTests */,
6874
031A8D72193DB57D00F4A6D2 /* Products */,
@@ -84,6 +90,7 @@
8490
031A8D76193DB57D00F4A6D2 /* AppDelegate.swift */,
8591
031A8D78193DB57D00F4A6D2 /* ViewController.swift */,
8692
031A8D7A193DB57D00F4A6D2 /* Main.storyboard */,
93+
03B0EEB019595EF00048D16D /* CameraViewController.swift */,
8794
0356839019498B730039E42D /* MapViewController.swift */,
8895
031A8D99193DDD4100F4A6D2 /* WebViewController.swift */,
8996
031A8D93193DCBE900F4A6D2 /* TableViewController.swift */,
@@ -222,6 +229,7 @@
222229
031A8D77193DB57D00F4A6D2 /* AppDelegate.swift in Sources */,
223230
0356839119498B730039E42D /* MapViewController.swift in Sources */,
224231
031A8D9A193DDD4100F4A6D2 /* WebViewController.swift in Sources */,
232+
03B0EEB119595EF00048D16D /* CameraViewController.swift in Sources */,
225233
);
226234
runOnlyForDeploymentPostprocessing = 0;
227235
};

SwiftExample/Base.lproj/Main.storyboard

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,42 @@
3131
</objects>
3232
<point key="canvasLocation" x="1048" y="-327"/>
3333
</scene>
34+
<!--Camera View Controller - Camera-->
35+
<scene sceneID="wfB-db-emn">
36+
<objects>
37+
<viewController id="hKc-Zw-bWd" customClass="CameraViewController" customModule="SwiftExample" customModuleProvider="target" sceneMemberID="viewController">
38+
<layoutGuides>
39+
<viewControllerLayoutGuide type="top" id="pMM-qG-X9u"/>
40+
<viewControllerLayoutGuide type="bottom" id="GLZ-Kf-J2k"/>
41+
</layoutGuides>
42+
<view key="view" contentMode="scaleToFill" id="Ve2-Gn-BbP">
43+
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
44+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
45+
<subviews>
46+
<imageView appearanceType="aqua" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XQE-kM-aDn">
47+
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
48+
</imageView>
49+
<button appearanceType="aqua" opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="THt-Oi-3QF">
50+
<rect key="frame" x="112" y="250" width="97" height="30"/>
51+
<state key="normal" title="Show Camera">
52+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
53+
</state>
54+
<connections>
55+
<action selector="cameraShow" destination="hKc-Zw-bWd" eventType="touchUpInside" id="Vd6-is-arg"/>
56+
</connections>
57+
</button>
58+
</subviews>
59+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
60+
</view>
61+
<navigationItem key="navigationItem" title="Camera" id="HBa-xH-yGn"/>
62+
<connections>
63+
<outlet property="backgroundImage" destination="XQE-kM-aDn" id="hD5-mh-LmV"/>
64+
</connections>
65+
</viewController>
66+
<placeholder placeholderIdentifier="IBFirstResponder" id="uwF-Py-j21" userLabel="First Responder" sceneMemberID="firstResponder"/>
67+
</objects>
68+
<point key="canvasLocation" x="1521" y="-315"/>
69+
</scene>
3470
<!--View Controller - Swift Example-->
3571
<scene sceneID="ufC-wZ-h7g">
3672
<objects>
@@ -70,6 +106,15 @@
70106
<segue destination="V4A-WZ-Px4" kind="push" id="6Gm-bN-Br1"/>
71107
</connections>
72108
</button>
109+
<button appearanceType="aqua" opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7MT-jK-mMs">
110+
<rect key="frame" x="196" y="373" width="88" height="30"/>
111+
<state key="normal" title="View camera">
112+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
113+
</state>
114+
<connections>
115+
<segue destination="hKc-Zw-bWd" kind="push" id="ahm-DB-Vle"/>
116+
</connections>
117+
</button>
73118
</subviews>
74119
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
75120
</view>
@@ -82,7 +127,7 @@
82127
<!--Web View Controller-->
83128
<scene sceneID="VOw-Q8-ULY">
84129
<objects>
85-
<viewController id="wf8-3g-qWu" customClass="WebViewController" sceneMemberID="viewController">
130+
<viewController id="wf8-3g-qWu" customClass="WebViewController" customModule="SwiftExample" customModuleProvider="target" sceneMemberID="viewController">
86131
<layoutGuides>
87132
<viewControllerLayoutGuide type="top" id="3O0-E3-k1G"/>
88133
<viewControllerLayoutGuide type="bottom" id="NIx-Kj-uFu"/>
@@ -100,7 +145,7 @@
100145
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
101146
</view>
102147
<connections>
103-
<outlet property="webView" destination="K28-0f-qxu" id="Rc9-3z-qZb"/>
148+
<outlet property="webView" destination="K28-0f-qxu" id="5wY-Vy-9Ts"/>
104149
</connections>
105150
</viewController>
106151
<placeholder placeholderIdentifier="IBFirstResponder" id="U1o-2E-873" userLabel="First Responder" sceneMemberID="firstResponder"/>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//
2+
// CameraViewController.swift
3+
// SwiftExample
4+
//
5+
// Created by Sachin Kesiraju on 6/24/14.
6+
// Copyright (c) 2014 Sachin Kesiraju. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import MobileCoreServices
11+
12+
class CameraViewController: UIViewController, UIImagePickerControllerDelegate, UIAlertViewDelegate, UINavigationControllerDelegate {
13+
14+
@IBOutlet var backgroundImage:UIImageView
15+
16+
var cameraUI:UIImagePickerController = UIImagePickerController()
17+
18+
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
19+
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
20+
// Custom initialization
21+
}
22+
23+
init(coder aDecoder: NSCoder!)
24+
{
25+
super.init(coder: aDecoder)
26+
}
27+
28+
//pragma mark - View
29+
30+
override func viewDidLoad() {
31+
super.viewDidLoad()
32+
self.presentCamera()
33+
// Do any additional setup after loading the view.
34+
}
35+
36+
override func didReceiveMemoryWarning() {
37+
super.didReceiveMemoryWarning()
38+
// Dispose of any resources that can be recreated.
39+
}
40+
41+
@IBAction func cameraShow()
42+
{
43+
self.presentCamera()
44+
}
45+
46+
//pragma mark - Camera
47+
48+
func presentCamera()
49+
{
50+
cameraUI = UIImagePickerController()
51+
cameraUI.delegate = self
52+
cameraUI.sourceType = UIImagePickerControllerSourceType.Camera
53+
cameraUI.mediaTypes = [kUTTypeImage]
54+
cameraUI.allowsEditing = false
55+
56+
self.presentViewController(cameraUI, animated: true, completion: nil)
57+
}
58+
59+
//pragma mark- Image
60+
61+
func imagePickerControllerDidCancel(picker:UIImagePickerController)
62+
{
63+
self.dismissViewControllerAnimated(true, completion: nil)
64+
}
65+
66+
func imagePickerController(picker:UIImagePickerController!, didFinishPickingMediaWithInfo info:NSDictionary)
67+
{
68+
var mediaType:NSString = info.objectForKey(UIImagePickerControllerEditedImage) as NSString
69+
var imageToSave:UIImage
70+
71+
imageToSave = info.objectForKey(UIImagePickerControllerOriginalImage) as UIImage
72+
73+
UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil)
74+
self.savedImage()
75+
self.dismissViewControllerAnimated(true, completion: nil)
76+
}
77+
78+
func savedImage()
79+
{
80+
var alert:UIAlertView = UIAlertView()
81+
alert.title = "Saved!"
82+
alert.message = "Your picture was saved to Camera Roll"
83+
alert.delegate = self
84+
alert.addButtonWithTitle("Awesome")
85+
alert.show()
86+
}
87+
88+
func alertView(alertView: UIAlertView!, didDismissWithButtonIndex buttonIndex: Int)
89+
{
90+
NSLog("Did dismiss button: %d", buttonIndex)
91+
self.presentCamera()
92+
}
93+
}

0 commit comments

Comments
 (0)