標籤:swift
擷取相機(swift)by 伍雪穎
@IBActionfunc takePhoto(sender:AnyObject) {
view.endEditing(true)
moveViewDown()
let imagePickerActionSheet =UIAlertController(title:"Snap/Upload Photo",
message: nil, preferredStyle: .ActionSheet)
ifUIImagePickerController.isSourceTypeAvailable(.Camera) {
let cameraButton =UIAlertAction(title:"Take Photo",
style: .Default) { (alert) ->Voidin
let imagePicker =UIImagePickerController()
imagePicker.delegate =self
imagePicker.sourceType = .Camera
self.presentViewController(imagePicker,
animated: true,
completion: nil)
}
imagePickerActionSheet.addAction(cameraButton)
}
let libraryButton =UIAlertAction(title:"Choose Existing",
style: .Default) { (alert) ->Voidin
let imagePicker =UIImagePickerController()
imagePicker.delegate =self
imagePicker.sourceType = .PhotoLibrary
self.presentViewController(imagePicker,
animated: true,
completion: nil)
}
imagePickerActionSheet.addAction(libraryButton)
let cancelButton =UIAlertAction(title:"Cancel",
style: .Cancel) { (alert) ->Voidin
}
imagePickerActionSheet.addAction(cancelButton)
presentViewController(imagePickerActionSheet, animated:true,
completion: nil)}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
擷取圖片(swift)