LoginSignup
0
0

More than 1 year has passed since last update.

タップさせて吹き出しをpopさせる。

Posted at

まずはpopさせるクラスを用意する

class PopViewController:UIViewController {
  override func viewDidLoad() {
        super.viewDidLoad()
         view.backgroundColor = .systemOrange
    }
}

遷移前の画面でコード作成。

//遷移先のVCをインスタンス化
  let viewController = PopViewController() //popoverで表示するViewController
//遷移方法をpopover
        viewController.modalPresentationStyle = .popover
//吹き出しのサイズを設定する
        viewController.preferredContentSize = CGSize(width: 200, height: 150)

        let presentationController = viewController.popoverPresentationController
//up 吹き出しを表示させる向きを設定する
        presentationController?.permittedArrowDirections = .up
//どこを基準に表示させるかのsourceViewを設定
        presentationController?.sourceView = cell
//吹き出しを表示させる位置を設定。
        presentationController?.sourceRect = cell.bounds
 //popoverさせるためのdelegateメソッド
        viewController.presentationController?.delegate = self
        present(viewController, animated: true, completion: nil)

必要なdelegateメソッドを用意


class ViewController: UIViewController, UIPopoverPresentationControllerDelegate{
//Iphoneで表示させる際のdelegateMethod
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return .none
    }

}

どこかで関数を発火すればOK!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0