我试图添加一个弹出窗口,当一个图像被点击,但它不断呈现模态。此问题/主题的每个答案建议添加adaptivePresentationStyleForPresentationController但它不适用于我。我正试图在iPhone上做到这一点。这是我的代码:Popover不断呈现模态
class ParkingInfoTableViewController: UITableViewController, UIPopoverPresentationControllerDelegate {
...
func presentPopover(sender:UITapGestureRecognizer) {
let storyboard : UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
let infoViewController = storyboard.instantiateViewControllerWithIdentifier("ImagesInfoPopupViewController")
infoViewController.modalPresentationStyle = .Popover
infoViewController.preferredContentSize = CGSizeMake(150, 75)
let popoverPresentationViewController = infoViewController.popoverPresentationController
popoverPresentationViewController?.permittedArrowDirections = .Any
popoverPresentationController?.delegate = self
popoverPresentationViewController?.sourceView = sender.view
popoverPresentationViewController?.sourceRect = CGRect(
x: sender.locationInView(sender.view).x,
y: sender.locationInView(sender.view).y,
width: 1,
height: 1)
self.presentViewController(infoViewController, animated: true, completion: nil)
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .None
}
与图像的单元是:
let cell = tableView.dequeueReusableCellWithIdentifier(AppConstants.moreInfoCellReusableIdentifier) as! MoreInfoTableViewCell
let tapped = UITapGestureRecognizer(target: self, action: #selector(presentPopover))
tapped.numberOfTapsRequired = 1
cell.securityImage.addGestureRecognizer(tapped)
cell.securityImage.userInteractionEnabled = true
return cell
还是不行... –