0

I'm using this function to show a popup view to select image from camera roll:

func selectImage(sender: UICollectionViewCell){
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum)
    {
        let imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self
        imagePickerController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePickerController.allowsEditing = false

            self.popOver = UIPopoverController(contentViewController: imagePickerController)
            self.popOver?.presentPopoverFromRect(sender.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)

    }
}

In the above code, sender.frame refers to the CollectionViewCell with the image icon (first one), but as you see, the popup view's arrow is located in the top.

enter image description here

I've tried UIPopoverArrowDirection.Down but the output was wired: enter image description here

This is how I call the selectImage():

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
//conditions to know if the first cell is selected
   selectImage(collectionView.cellForItemAtIndexPath(indexPath)!)
}
Maysam
  • 7,246
  • 13
  • 68
  • 106
  • 1
    replace this line by this: `self.popOver?.presentPopoverFromRect(sender.frame, inView: sender.superview, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)` – Nishant Sep 14 '15 at 14:16
  • @Nishant Post is as the answer so I can mark it. – Maysam Sep 14 '15 at 14:20

1 Answers1

0

A more generic way of presenting ANY popover is as shown in the following code snippet:

self.popOver?.presentPopoverFromRect(sender.frame, inView: sender.superview, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
Nishant
  • 12,529
  • 9
  • 59
  • 94