show action sheet for changeCoverAction

This commit is contained in:
nixzhu
2015-07-21 16:09:14 +08:00
parent bd07a365b0
commit 9eefda07dd
2 changed files with 47 additions and 13 deletions
@@ -98,7 +98,7 @@ class EditProfileViewController: UIViewController {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
self?.presentViewController(imagePicker, animated: true, completion: nil)
@@ -117,7 +117,7 @@ class EditProfileViewController: UIViewController {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.sourceType = .Camera
imagePicker.allowsEditing = false
self?.presentViewController(imagePicker, animated: true, completion: nil)
@@ -128,18 +128,52 @@ class SkillHomeViewController: CustomNavigationBarViewController {
headerView.changeCoverAction = { [weak self] in
let openCameraRoll: ProposerAction = { [weak self] in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .PhotoLibrary
imagePicker.delegate = self
self?.presentViewController(imagePicker, animated: true, completion: nil)
}
}
let alertController = UIAlertController(title: NSLocalizedString("Change skill cover", comment: ""), message: nil, preferredStyle: .ActionSheet)
proposeToAccess(.Photos, agreed: openCameraRoll, rejected: {
self?.alertCanNotAccessCameraRoll()
})
let choosePhotoAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Choose Photo", comment: ""), style: .Default) { action -> Void in
let openCameraRoll: ProposerAction = { [weak self] in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
self?.presentViewController(imagePicker, animated: true, completion: nil)
}
}
proposeToAccess(.Photos, agreed: openCameraRoll, rejected: {
self?.alertCanNotAccessCameraRoll()
})
}
alertController.addAction(choosePhotoAction)
let takePhotoAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Take Photo", comment: ""), style: .Default) { action -> Void in
let openCamera: ProposerAction = { [weak self] in
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
imagePicker.allowsEditing = false
self?.presentViewController(imagePicker, animated: true, completion: nil)
}
}
proposeToAccess(.Camera, agreed: openCamera, rejected: {
self?.alertCanNotOpenCamera()
})
}
alertController.addAction(takePhotoAction)
let cancelAction: UIAlertAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .Cancel) { action -> Void in
self?.dismissViewControllerAnimated(true, completion: nil)
}
alertController.addAction(cancelAction)
self?.presentViewController(alertController, animated: true, completion: nil)
}
automaticallyAdjustsScrollViewInsets = false