获取相机(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)
}
版权声明:本文为博主原创文章,未经博主允许不得转载。