2015-12-15 3 views
0

У меня возникли некоторые проблемы с моей ActionSheet. На iPhone он отлично работает, но на iPad он просто падает.ActionSheet аварии на IPad (кнопка камеры)

У меня есть кнопка для отображения камеры, но я не в состоянии правильно сделать это на IPad.

Код:

class pictureViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextViewDelegate { 
    @IBOutlet weak var picture: UIImageView! 
    override func viewDidLoad() { 
    } 

    @IBAction func choosePictureAction(sender: AnyObject) { 
     let alertPictureFrom = UIAlertController(title: "De dónde sacar la foto?", message: "", preferredStyle: UIAlertControllerStyle.ActionSheet) 
     presentViewController(alertPictureFrom, animated: true, completion: nil) 
     alertPictureFrom.addAction(UIAlertAction(title: "Cámara", style: .Default, handler: {action in 
      let picker = UIImagePickerController() 
      picker.sourceType = .Camera 
      picker.delegate = self 
      picker.allowsEditing = true 
      self.presentViewController(picker, animated: true, completion: nil) 
     })) 

     alertPictureFrom.addAction(UIAlertAction(title: "Galería", style: .Default, handler: {action in 
      let picker = UIImagePickerController() 
      picker.sourceType = .PhotoLibrary 
      picker.delegate = self 
      picker.allowsEditing = true 
      self.presentViewController(picker, animated: true, completion: nil) 
     })) 
    } 

    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) { 
     picture.image = image 
     picker.dismissViewControllerAnimated(true, completion: nil) 
    } 

} 

Ваша заявка представлена ​​UIAlertController() стиля UIAlertControllerStyleActionSheet. ModalPresentationStyle UIAlertController с этим стилем - UIModalPresentationPopover. Вы должны предоставить информацию о местоположении для этого popover через popoverPresentationController контроллера контролера. Вы должны указать либо sourceView, и sourceRect, либо barButtonItem. Если эта информация неизвестна при представлении контроллера предупреждений, вы можете указать ее в методе UIPopoverPresentationControllerDelegate -prepareForPopoverPresentation.

+0

Вы должны предоставить информацию о местоположении этого пирог через popoverPresentationController диспетчера предупреждений. –

ответ

2

В сообщении об ошибке говорит: «Вы должны предоставить либо SourceView и sourceRect или barButtonItem» через popoverPresentationController

Это позволит UIKit знать, где представить поповер с, и тогда вы получите, что прекрасное поведение, когда popover появляется в прикрепленном к указанном вами элементе.

Например:

alertPictureFrom.popoverPresentationController?.sourceRect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0) 
alertPictureFrom.popoverPresentationController?.sourceView = self.view 

Теперь этот пример полностью для демонстрационных целей, вам нужно будет выяснить sourceView и sourceRect для пирог.

Справочная документация:

+0

Отличная работа !!!!! – FactorJose

+0

Это работает для меня в первый раз, однако, если ActionSheet представлен снова, я снова получаю ошибку. Я устанавливаю sourceView и sourceRect в методе UIPopoverPresentationControllerDelegate prepareForPopoverPresentation. –

+0

О, просто разобрался. Он работает, если я устанавливаю sourceView и sourceRect не в методе делегата. В любом случае спасибо! –

0

Попытка (в случае UIButton):

picker.popoverPresentationController?.sourceView = testButton 
picker.popoverPresentationController?.sourceRect = testButton.bounds 
picker.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Right.bounds 
0

ваш дефект ошибки из-за UIActionSheet

UIActionSheet не поддерживается в ipad. для iphone нечего делать в iphone UIActionSheet работать нормально для IPAD UIActionSheet открыт в другой точке зрения, как

UIActionSheetObjects.showFromRect(CGRectMake(150, 0, 300,200) ,inView:self.view, animated:YES) 

и он будет работать для вас ...

Смежные вопросы