Photo
1 //MARK:-Take pictures2 func fromphotograph ()3 {4 ifuiimagepickercontroller.issourcetypeavailable (. Camera)5 {6 //Create a picture controller7Let picker =Uiimagepickercontroller ()8 9 //Set up proxyTenPicker.Delegate= Self One A //Set Source -Picker.sourcetype =Uiimagepickercontrollersourcetype.camera - the - //Setting the lens - ifuiimagepickercontroller.iscameradeviceavailable (Uiimagepickercontrollercameradevice.front) - { +Picker.cameradevice =Uiimagepickercontrollercameradevice.front - } + A //Setting the Flash atPicker.cameraflashmode =Uiimagepickercontrollercameraflashmode.on - - //Allow Editing -Picker.allowsediting =true; - - //turn on the camera inSelf.presentviewcontroller (picker, animated:true, completion: {(), Voidinch - to }) + - } the Else * { $Let Aler = Uialertview (title:"can't find the camera!", Message:nil,Delegate: Nil, Cancelbuttontitle:"Determine")Panax Notoginseng aler.show () - } the } + A //MARK:-Uiimagepickercontrollerdelegate the + //Select image after successful agent - func Imagepickercontroller (picker:uiimagepickercontroller, didfinishpickingmediawithinfo info: [NSOBJECT:ANYOB Ject]) $ { $ //View Info Object - println (Info) - the //get the selected artwork - //Let image = Info[uiimagepickercontrolleroriginalimage] as UIImageWuyi the //May 2015 after 2 revision -Let image = Info[uiimagepickercontrolleroriginalimage] as!UIImage Wu - //assignment, picture view display Picture AboutPicview.image =Image $ - //Picture Controller Exit -Picker.dismissviewcontrolleranimated (true, completion: {(), Voidinch - A }) + } the - //canceling the picture controller agent $ func imagepickercontrollerdidcancel (picker:uiimagepickercontroller) the { the //Picture Controller Exit thePicker.dismissviewcontrolleranimated (true, completion: {(), Voidinch the - }) in } the the About //MARK:-Uiactionsheetdelegate the func actionsheet (Actionsheet:uiactionsheet, Clickedbuttonatindex buttonindex:int) the { the ifButtonindex! =Actionsheet.cancelbuttonindex + { - ifButtonindex = =1 //Select from albums the {Bayi self.fromalbum () the}Else ifButtonindex = =2 //Take Pictures the { - self.fromphotograph () - } the } the}
iOS Development--Practical technical article Swift & photo