Popover location from my tap (Swift)
How can I make it so that when I click on the link then the popover would appear next to the click as shown in the picture?
I tried to add it but then it is displayed in the upper left corner
optionMenu.popoverPresentationController?.sourceView = self.view
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
if (URL.scheme?.contains("mailto"))! {
let optionMenu = UIAlertController(title: nil, message: "\(URL)", preferredStyle: .actionSheet)
// 2
let NewAction = UIAlertAction(title: "New Mail Message", style: .default, handler: { (alert: UIAlertAction!) -> Void in
print("New Mail Message")
UIApplication.shared.open(URL)
})
//
let CopyAction = UIAlertAction(title: "Copy", style: .default, handler: { (alert: UIAlertAction!) -> Void in
print("Copy Email")
UIPasteboard.general.string = "\(URL)"
})
//
let CancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: { (alert: UIAlertAction!) -> Void in
print("Cancelled")
})
// 4
optionMenu.addAction(NewAction)
optionMenu.addAction(CopyAction)
optionMenu.addAction(CancelAction)
// 5
self.present(optionMenu, animated: true) {
print("Email menu presented")
}
} else {
//
}
}