码迷,mamicode.com
首页 > 移动开发 > 详细

ios开发——实用技术篇Swift篇&拍照

时间:2015-06-07 23:08:22      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

拍照

 

 1     // MARK: - 拍照
 2     func fromPhotograph()
 3     {
 4         if UIImagePickerController.isSourceTypeAvailable(.Camera)
 5         {
 6             //创建图片控制器
 7             let picker = UIImagePickerController()
 8             
 9             //设置代理
10             picker.delegate = self
11             
12             //设置来源
13             picker.sourceType = UIImagePickerControllerSourceType.Camera
14             
15             
16             //设置镜头
17             if UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front)
18             {
19                 picker.cameraDevice = UIImagePickerControllerCameraDevice.Front
20             }
21             
22             //设置闪光灯
23             picker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.On
24             
25             //允许编辑
26             picker.allowsEditing = true;
27             
28             //打开相机
29             self.presentViewController(picker, animated: true, completion: { () -> Void in
30                 
31             })
32             
33         }
34         else
35         {
36             let aler = UIAlertView(title: "找不到相机!", message: nil, delegate: nil, cancelButtonTitle: "确定")
37             aler.show()
38         }
39     }
40     
41     // MARK: - UIImagePickerControllerDelegate
42     
43     //选择图片成功之后代理
44     func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
45     {
46         //查看info对象
47         println(info)
48         
49         //获取选择的原图
50 //        let image = info[UIImagePickerControllerOriginalImage] as UIImage
51         
52         //2015年5月2后修改
53         let image = info[UIImagePickerControllerOriginalImage] as! UIImage
54         
55         //赋值,图片视图显示图片
56         picView.image = image
57         
58         //图片控制器退出
59         picker.dismissViewControllerAnimated(true, completion: { () -> Void in
60             
61         })
62     }
63     
64     //取消图片控制器代理
65     func imagePickerControllerDidCancel(picker: UIImagePickerController)
66     {
67         //图片控制器退出
68         picker.dismissViewControllerAnimated(true, completion: { () -> Void in
69             
70         })
71     }
72     
73     
74     // MARK: - UIActionSheetDelegate
75     func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)
76     {
77         if buttonIndex != actionSheet.cancelButtonIndex
78         {
79             if buttonIndex == 1  //从相册选
80             {
81                 self.fromAlbum()
82             }else if buttonIndex == 2 //拍照
83             {
84                 self.fromPhotograph()
85             }
86         }
87     }

 

 

 

ios开发——实用技术篇Swift篇&拍照

标签:

原文地址:http://www.cnblogs.com/iCocos/p/4559306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!