1,打开相机拍照
通过设置图片控制器UIImagePickerController的来源为UIImagePickerControllerSourceType.Camera,便可以打开相机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import
UIKit
class
ViewController
:
UIViewController
,
UIImagePickerControllerDelegate
override
func
viewDidLoad() {
super
.viewDidLoad()
}
//拍照
@IBAction
fromPhotograph(sender:
AnyObject
) {
if
UIImagePickerController
.isSourceTypeAvailable(.
Camera
){
//创建图片控制器
let
picker =
UIImagePickerController
()
//设置代理
picker.delegate =
self
//设置来源
picker.sourceType =
UIImagePickerControllerSourceType
.
Camera
//允许编辑
picker.allowsEditing =
true
//打开相机
self
.presentViewController(picker,animated:
true
Void
in
})
}
else
{
println
(
"找不到相机"
)
}
}
didReceiveMemoryWarning() {
.didReceiveMemoryWarning()
}
}
|
2,调用前置,后置摄像头
相机默认使用后置摄像头,可以设置UIImagePickerControllerCameraDevice类型来使用前置摄像头或后置摄像头。
像iTouch设备不具备前置摄像头,我们可以事先判断下是否支持前置。
//如果有前置摄像头则调用前置摄像头
.isCameraDeviceAvailable(
UIImagePickerControllerCameraDevice
Front
){
picker.cameraDevice =
Front
3,设置闪光灯
通过cameraFlashMode属性可以设置闪光灯:开启/关闭/自动
原文出自: www.hangge.com 转载请保留原文链接: http://www.hangge.com/blog/cache/detail_770.html 原文链接:https://www.f2er.com/swift/321586.html 猜你在找的Swift相关文章 |