拍照

     // MARK: - 拍照
     func fromPhotograph()
     {
         if UIImagePickerController.isSourceTypeAvailable(.Camera)
         {
             //创建图片控制器
             let picker = UIImagePickerController()

             //设置代理
             picker.delegate = self

             //设置来源
             picker.sourceType = UIImagePickerControllerSourceType.Camera

             //设置镜头
             if UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front)
             {
                 picker.cameraDevice = UIImagePickerControllerCameraDevice.Front
             }

             //设置闪光灯
             picker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.On

             //允许编辑
             picker.allowsEditing = true;

             //打开相机
             self.presentViewController(picker, animated: true, completion: { () -> Void in

             })

         }
         else
         {
             let aler = UIAlertView(title: "找不到相机!", message: nil, delegate: nil, cancelButtonTitle: "确定")
             aler.show()
         }
     }

     // MARK: - UIImagePickerControllerDelegate

     //选择图片成功之后代理
     func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])
     {
         //查看info对象
         println(info)

         //获取选择的原图
 //        let image = info[UIImagePickerControllerOriginalImage] as UIImage

         //2015年5月2后修改
         let image = info[UIImagePickerControllerOriginalImage] as! UIImage

         //赋值,图片视图显示图片
         picView.image = image

         //图片控制器退出
         picker.dismissViewControllerAnimated(true, completion: { () -> Void in

         })
     }

     //取消图片控制器代理
     func imagePickerControllerDidCancel(picker: UIImagePickerController)
     {
         //图片控制器退出
         picker.dismissViewControllerAnimated(true, completion: { () -> Void in

         })
     }

     // MARK: - UIActionSheetDelegate
     func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)
     {
         if buttonIndex != actionSheet.cancelButtonIndex
         {
               //从相册选
             {
                 self.fromAlbum()
             } //拍照
             {
                 self.fromPhotograph()
             }
         }
     }
 

ios开发——实用技术篇Swift篇&拍照的更多相关文章

  1. ios开发——实用技术篇Swift篇&播放MP3

    播放MP3 // MARK: - 播放MP3 /*----- mp3 ------*/ //定时器- func updateTime() { //获取音频播放器播放的进度,单位秒 var cuTime ...

  2. ios开发——实用技术篇Swift篇&照片选择

    照片选择 // MARK: - 选择照片 /*----- 选择照片 ------*/ @IBAction func addImageButtonClick() { let actionSheet = ...

  3. ios开发——实用技术篇Swift篇&地址薄、短信、邮件

    //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...

  4. ios开发——实用技术篇Swift篇&系统声音

    系统声音 // MARK: - 系统声音 /*----- 系统声音 ------*/ @IBAction func systemSound() { //建立的SystemSoundID对象 var s ...

  5. ios开发——实用技术篇Swift篇&视频

    视频 // MARK: - 播放视频 /*----- 播放视频 ------*/ func moviePlayerPreloadFinish(notification:NSNotification) ...

  6. ios开发——实用技术篇Swift篇&录音

    录音 // MARK: - 录音 /*----- 录音 ------*/ var recorder:AVAudioRecorder? //录音器 var player:AVAudioPlayer? / ...

  7. ios开发——实用技术篇Swift篇&加速计和陀螺仪

    加速计和陀螺仪 //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnim ...

  8. ios开发——实用技术篇Swift篇&多点触摸与手势识别

    多点触摸与手势识别 //点击事件 var atap = UITapGestureRecognizer(target: self, action: "tapDo:") self.vi ...

  9. ios开发——实用技术篇OC篇&iOS的主要框架

    iOS的主要框架         阅读目录 Foundation框架为所有的应用程序提供基本系统服务 UIKit框架提供创建基于触摸用户界面的类 Core Data框架管着理应用程序数据模型 Core ...

随机推荐

  1. 认识Agile,Scrum和DevOps

    If everything's under control you are going too slow. 当今的开发,要求faster and faster.所以我们要Agile,become Ag ...

  2. pthread_cond_timedwait时间设置

    最近工作中需要在ACodec中起一个pthread,并每间隔100ms统计一次buffer的状态,在程序中使用pthread_cond_timedwait来设置时间间隔,但在使用中发现当超时时间设置成 ...

  3. 基于Linux2.6内核的加密容器法保护文件方法

            本文出自 "李晨光原创技术博客" 博客,谢绝转载!

  4. LeetCode100:Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  5. 第三次作业之Calculator项目随笔

    附:Github的链接:https://github.com/mingyueanyao/object-oriented/tree/master/Calculator 1.初见题目: 第一眼看到题目最大 ...

  6. POJ 1852 Ants (等价思考)

    题意:在一根杆上有 n 只蚂蚁,速度为1,方向不定,如果相碰,则反向运动,问你最长的时间和最短时间,所有蚂蚁都掉下杆去. 析:换个方法想,如果两只蚂蚁相碰了,会有什么现象?其实就和没有碰撞是一样的,没 ...

  7. (图解版)SQL Server数据库备份与还原

        本文介绍了SQL Server数据库备份的两种方式.一种是直接拷贝数据库中的文件mdf 和日志文件ldf,另一种是生成脚本语言. 第一种方式:     选中需要备份的数据库,将数据库从运行的数 ...

  8. UVa 297 - Quadtrees

    题目:利用四叉树处理图片,给你两张黑白图片的四叉树,问两张图片叠加后黑色的面积. 分析:搜索.数据结构.把图片分成1024块1*1的小正方形,建立一位数组记录对应小正方形的颜色. 利用递归根据字符串, ...

  9. hdoj 5392 Infoplane in Tina Town

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...

  10. Visual Studio无法添加断点

    今天在写代码的时候突然发现无法添加断点,更加详细的场景是“按F9可以添加调试行,但是断点不显示,且显示代码行数左边的灰色区域不见了”找了各种方法也没有解决,然后重启.修复甚至重装都不行,最后在万千网页 ...