The view of the controller source changes each time it is displayed.

This is what should be my view controller:

enter image description here

This is what sometimes happens:

enter image description here

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?

+5
source share
2 answers

I found the problem, in fact the missing restriction on the regular regular size class caused this problem, I fixed it by adding the distance to the bottom layout guide to the part that was used for inappropriate.

Thanks everyone for your idea.

+3
source

You can use the container view instead of the view controller view. You can create them programmatically or in the interface builder (see Apple docs ).

+1
source

Source: https://habr.com/ru/post/1259150/


All Articles