I want to display pop up in a centre of the screen. The below image displaying it's moving the bit of left side.
I have tried below code to display popover controller.
func displayPopoverVC() {
let popOver = popupArtistStoryboard.instantiateViewController(withIdentifier: "MeasurementPopupVC") as! MeasurementPopupVC
popOver.modalPresentationStyle = .popover
popOver.popoverPresentationController?.permittedArrowDirections = .up
popOver.popoverPresentationController?.sourceView = btnTmpMeasurement
popOver.popoverPresentationController?.sourceRect = CGRect.init(x: 0, y: 0, width: btnTmpMeasurement.frame.size.width, height: btnTmpMeasurement.frame.size.height)
if (DeviceType.IS_IPAD_PRO || DeviceType.IS_IPAD) {
popOver.preferredContentSize = CGSize(width: 240, height: 50.0)
} else {
popOver.preferredContentSize = CGSize(width: 325, height: 30.0)
}
popOver.delegate = self
popOver.popoverPresentationController?.delegate = self
popOver.arrOfMeasurementData = [String]()
if let presentation = popOver.popoverPresentationController {
presentation.backgroundColor = UIColor(red: 236.0/255.0, green: 236.0/255.0, blue: 236.0/255.0, alpha: 0.5)
}
self.present(popOver, animated: true) {}
}
Please correct me if I've written any incorrect code.