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
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
UINavigationControllerDelegate
{
override
func
viewDidLoad() {
super
.viewDidLoad()
}
//拍照
@IBAction
fromPhotograph(sender:
AnyObject
) {
if
UIImagePickerController
.isSourceTypeAvailable(.
Camera
){
//创建图片控制器
let
picker =
UIImagePickerController
()
//设置代理
picker.delegate =
self
//设置来源
//允许编辑
picker.allowsEditing =
true
//打开相机
self
.presentViewController(picker,animated:
true
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,completion: { () ->
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 相关文章软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...
|