This is what should be my view controller:

This is what sometimes happens:

I want to display the view controller in a circle, however, almost every time a view controller in a circle ( ResultViewController ) is ResultViewController , it is different, although its properties do not change at all. Here is my code:
func openCircle(withCenter center: CGPoint, dataSource: ([Items], Int, String)){ self.addCircle(withCenter: center, dataSource: dataSource) } func addCircle(withCenter circleCenter: CGPoint, dataSource: ([Items], Int, String)) { let longerSide = fmax(view.frame.size.height, view.frame.size.width) let shorterSide = fmin(view.frame.size.height, view.frame.size.width) let circleRadius = longerSide / 2 var resultViewOrigin = CGPoint() var resultViewSize = CGSize() if UIDevice.current.userInterfaceIdiom == .pad { let rectWidth = shorterSide / 2 let rectHeight = sqrt(abs(circleRadius * circleRadius - rectWidth * rectWidth)) + view.frame.size.height - circleCenter.y resultViewSize = CGSize(width: rectWidth, height: rectHeight) resultViewOrigin = CGPoint(x: (view.frame.size.width - rectWidth) / 2, y: view.frame.size.height - rectHeight) } else { resultViewOrigin = CGPoint(x: 0.0, y: 0.0) resultViewSize = CGSize(width: view.frame.size.width, height: view.frame.size.height) } let resultViewController = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "ResultVC") as! ResultViewController resultViewController.transitioningDelegate = self resultViewController.modalPresentationStyle = .custom resultViewController.dataSource = dataSource resultViewController.view.frame = CGRect(origin: resultViewOrigin, size: resultViewSize) transition.circle = UIView() transition.startingPoint = circleCenter transition.radius = circleRadius transition.circle.frame = circleFrame(radius: transition.radius, center: transition.startingPoint) present(resultViewController, animated: true) }
This works well on the iPhone, not on the iPad, what's the problem?
source share