Поповер не работает в Swift 4 - PullRequest
0 голосов
/ 29 июня 2018

Я использую UIPopoverPresentationControllerDelegate, чтобы показать мой поповер, он работает нормально, но не может управлять шириной и высотой всплывающего viewController. И как установить презентацию в текущем контексте ??

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let showObjectVC = storyboard?.instantiateViewController(withIdentifier: "ShowActorDetail") as! ShowActorDetailsViewController
    showObjectVC.modalPresentationStyle = .popover

    showObjectVC.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath)
    showObjectVC.popoverPresentationController?.delegate = self
    showObjectVC.preferredContentSize = CGSize(width: 400, height: 300)

    present(showObjectVC, animated: true, completion: nil)
}

Ответы [ 2 ]

0 голосов
/ 06 июля 2018

вместо использования preferredContentSize попробуйте использовать свойство sourceRect, например UIPopoverPresentationController,

showObjectVC.popoverPresentationController?.sourceRect = tableView.cellForRow(at: indexPath)!.frame

Обязательно указывайте рамку ячейки так, как вам нужно, чтобы всплывающее окно показывало в нужной вам позиции.

0 голосов
/ 29 июня 2018

Вы можете попробовать другой подход:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let showObjectVC = storyboard?.instantiateViewController(withIdentifier: "ShowActorDetail") as! ShowActorDetailsViewController
    // your logic
    presentViewControllerAsPopUp(showObjectVC)
}

private func presentViewControllerAsPopUp(_ vc: UIViewController) {
    vc.modalPresentationStyle = .overCurrentContext
    vc.modalTransitionStyle = .crossDissolve
    //self.definesPresentationContext = true
    self.present(vc, animated: true, completion: nil)
}

В ShowActorDetailsViewController вы можете сделать UIView с нужным размером и цветным фоном.

...