UIActionSheet 其实已经弃用,但是我们还在适配ios7 所以还在用着, 遇到过两次ipad 弹不出的问题, 然后时间久了会忘记,特此记录一下
创建用
let actionSheet = UIActionSheet()
actionSheet.delegate = self
actionSheet.actionSheetStyle = UIActionSheetStyle.default
actionSheet.addButton(withTitle: "取消")
actionSheet.addButton(withTitle: "从手机相册选择")
actionSheet.addButton(withTitle: "拍照")
actionSheet.cancelButtonIndex = 0
actionSheet.show(in: (controller?.view)!)
代理方法改用diss 的那个
func actionSheet(_ actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {
if buttonIndex == 0{
return
}
let picker = UIImagePickerController()
if buttonIndex == 1{
picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
}else if buttonIndex == 2{
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == false{
return
}
picker.sourceType = UIImagePickerControllerSourceType.camera
}
picker.delegate = self
picker.allowsEditing = true
self.findController().present(picker, animated: true) {
}
}
// 手机上ok 但是ipad 报错
// func actionSheet(_ actionSheet: UIActionSheet, clickedButtonAt buttonIndex: Int){
// Getdevice.println("clickindex \(buttonIndex)")
// if buttonIndex == 0{
// return
// }
// let picker = UIImagePickerController()
//
// if buttonIndex == 1{
// picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
// }else if buttonIndex == 2{
// if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) == false{
// return
// }
// picker.sourceType = UIImagePickerControllerSourceType.camera
// }
// picker.delegate = self
// picker.allowsEditing = true
// self.findController().present(picker, animated: true) {
//
// }
// }
文章评论