1

It's well known that in order to present UIAlertController with preferredStyle: .actionSheet, it's a good practice to set an anchor using the next code:

 popover.sourceView = view
 popover.sourceRect = view.bounds

In my case, the view is UIImageView, it's size is 44x44, but its image (three vertical dots) is very thin (its size is 4x24). So the view is mostly transparent. As a result, popover "points" to empty space. (Note that I am using red color to show fully transparent area)

enter image description here

Ideally, popover's arrow should point to the central white dot. But I do not know how to achieve it. I tried to modify sourceRect as follows:

popover.sourceRect = CGRect(x: view.bounds.midX - 1,
                            y: view.bounds.midY - 1,
                            width: 2,
                            height: 2)

but it points to the top white dot for some reason:

enter image description here

How can I make it pointing to the desired point?

Nick
  • 3,205
  • 9
  • 57
  • 108

1 Answers1

1

The sourceRect worked for me, i just used the y coordinates to position the arrow and it worked for me.

popover.sourceRect =  CGRect(x: 0, y: yourPosition, width: 0, height: 0)

You can also have a look at this.

daris mathew
  • 429
  • 5
  • 18