how to center a popoverview in swift

前端 未结 10 1727
终归单人心
终归单人心 2020-12-04 16:42

I have the following code to show a popoverview (dialog) without an arrow, which works fine. The only problem is, that the dialog is shown in the top left (IPad). I would li

10条回答
  •  春和景丽
    2020-12-04 17:17

    Swift 4 implementation for center Popover controller

    let navigationController = UINavigationController(rootViewController: controller)
    
     navigationController.modalPresentationStyle = .popover      
     navigationController.modalPresentationStyle = UIModalPresentationStyle.popover
     let popover = navigationController.popoverPresentationController
     controller.preferredContentSize = CGSize(width:500,height:600) //manage according to Device like iPad/iPhone
     popover?.delegate = self
     popover?.sourceView = self.view
     popover?.sourceRect = CGRect(x: view.center.x, y: view.     .y, width: 0, height: 0)
     popover?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
    
     self.present(navigationController, animated: true, completion: nil)
    

提交回复
热议问题