ios開發——實用技術篇Swift篇&拍照

來源:互聯網
上載者:User

標籤:

拍照

 

 1     // MARK: - 拍照 2     func fromPhotograph() 3     { 4         if UIImagePickerController.isSourceTypeAvailable(.Camera) 5         { 6             //建立圖片控制器 7             let picker = UIImagePickerController() 8              9             //設定代理10             picker.delegate = self11             12             //設定來源13             picker.sourceType = UIImagePickerControllerSourceType.Camera14             15             16             //設定鏡頭17             if UIImagePickerController.isCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front)18             {19                 picker.cameraDevice = UIImagePickerControllerCameraDevice.Front20             }21             22             //設定閃光燈23             picker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.On24             25             //允許編輯26             picker.allowsEditing = true;27             28             //開啟相機29             self.presentViewController(picker, animated: true, completion: { () -> Void in30                 31             })32             33         }34         else35         {36             let aler = UIAlertView(title: "找不到相機!", message: nil, delegate: nil, cancelButtonTitle: "確定")37             aler.show()38         }39     }40     41     // MARK: - UIImagePickerControllerDelegate42     43     //選擇圖片成功之後代理44     func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject])45     {46         //查看info對象47         println(info)48         49         //擷取選擇的原圖50 //        let image = info[UIImagePickerControllerOriginalImage] as UIImage51         52         //2015年5月2後修改53         let image = info[UIImagePickerControllerOriginalImage] as! UIImage54         55         //賦值,圖片視圖顯示圖片56         picView.image = image57         58         //圖片控制器退出59         picker.dismissViewControllerAnimated(true, completion: { () -> Void in60             61         })62     }63     64     //取消圖片控制器代理65     func imagePickerControllerDidCancel(picker: UIImagePickerController)66     {67         //圖片控制器退出68         picker.dismissViewControllerAnimated(true, completion: { () -> Void in69             70         })71     }72     73     74     // MARK: - UIActionSheetDelegate75     func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)76     {77         if buttonIndex != actionSheet.cancelButtonIndex78         {79             if buttonIndex == 1  //從相簿選80             {81                 self.fromAlbum()82             }else if buttonIndex == 2 //拍照83             {84                 self.fromPhotograph()85             }86         }87     }

 

 

 

ios開發——實用技術篇Swift篇&拍照

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.