获取相机(swift)
by 伍雪颖
@IBAction
func
takePhoto(sender:
AnyObject
) {
view . endEditing ( true )
moveViewDown ()
let imagePickerActionSheet = UIAlertController (title: "Snap/Upload Photo" ,
message: nil ,preferredStyle: . ActionSheet )
if UIImagePickerController . isSourceTypeAvailable (. Camera ) {
let cameraButton = UIAlertAction (title: "Take Photo" ,
style: . Default ) { (alert) -> Void in
let imagePicker = UIImagePickerController ()
imagePicker. delegate = self
imagePicker. sourceType = . Camera
self . presentViewController (imagePicker,
animated: true ,
completion: nil )
}
imagePickerActionSheet. addAction (cameraButton)
}
let libraryButton = "Choose Existing" ,129)">PhotoLibrary
addAction (libraryButton)
let cancelButton = "Cancel" ,129)">Cancel ) { (alert) -> in
}
imagePickerActionSheet. addAction (cancelButton)
presentViewController (imagePickerActionSheet,animated: nil )
view . endEditing ( true )
moveViewDown ()
let imagePickerActionSheet = UIAlertController (title: "Snap/Upload Photo" ,
message: nil ,preferredStyle: . ActionSheet )
if UIImagePickerController . isSourceTypeAvailable (. Camera ) {
let cameraButton = UIAlertAction (title: "Take Photo" ,
style: . Default ) { (alert) -> Void in
let imagePicker = UIImagePickerController ()
imagePicker. delegate = self
imagePicker. sourceType = . Camera
self . presentViewController (imagePicker,
animated: true ,
completion: nil )
}
imagePickerActionSheet. addAction (cameraButton)
}
let libraryButton = "Choose Existing" ,129)">PhotoLibrary
addAction (libraryButton)
let cancelButton = "Cancel" ,129)">Cancel ) { (alert) -> in
}
imagePickerActionSheet. addAction (cancelButton)
presentViewController (imagePickerActionSheet,animated: nil )
}