swiftpopviewcontroller

Wrong direction arrow when popup shows up


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)!)
}

Solution

  • 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)