I have a dynamic button configuration that automatically adjusts to the width and height based on the auto layout restrictions set in the storyboard. When the buttons in the portrait have equal width and height, so that the frame is perfectly square, and when the device rotates into the landscape, the buttons become shorter and wider. I set cornerRadius on the button layers so that they are completely circular when they were in the portrait, and it works well, but when I turn to the landscape, the corner radius clearly doesn't look right. I need to change this so that it becomes oval. The problem is that no matter where I try to put this code, I can not get the correct width and height of the buttons after the rotation. I want this to happen during the rotation of the device - do not want to wait for the rotation to complete. Ideally, cornerRadius will animate the change during the transition animation.
If I use viewWillLayoutSubviews or viewDidLayoutSubviews , it gets the button frame correctly when the application starts, but when turning to the album, this method is called before the button frame is updated for the new orientation, t calculate the correct angular radius.
If I use viewWillTransitionToSize:withTransitionCoordinator: or willTransitionToTraitCollection:withTransitionCoordinator: or willRotateToInterfaceOrientation , it is not called when the application starts, and when it is rotated, it is called before the frame is updated for the new size.
If I use willAnimateRotationToInterfaceOrientation , it is not called when the application starts, but when the device is rotated, it correctly receives a new button frame. But this method is outdated.
So the question is, what method can you use to set the button properties based on the size of the button when the rotation is completed, which is called before the rotation is completed?
Please note that you need to call it for every change of orientation, and not just for changing the class size (the rotating iPad does not change the class size). I only need to support iOS 8.0 +.
This is the code that I put in the methods to find out if it gets the correct size:
println("\(button.frame.size.width) x \(button.frame.size.height)")
ios ios8 swift size-classes screen-rotation
Joey
source share