Reputation: 943
I'm reworking an existing project to allow for screen rotation and multiple devices but whenever I rotate the screen in the simulator, the buttons disappear. A started from scratch toy example works but not the active project. What things could cause this? Everything is in Storyboard with auto layout.
Upvotes: 2
Views: 3421
Reputation: 2928
as per your question first you must check whether you application is using size class or not and one other thing please check that constraints are breaking or not while changing orientation.
It the issue not breaking of constraints the follow below procedure. But if you can see something like this as per below image then you need to change constraints only.
Secondly if not then you need to use size class by selecting Main.storyboard or ViewController.xib.
Then you need to go to file inspector and select Use Size Class below Use Auto Layout.
For making application for multiple device with orientation size class comes in handy.
Please have a look at images below.
Application without size class
Result how UI will be displayed in device.
Enabling size Class from File Inspector.
Once you have made changes and as now ViewController will be able to change the constraints according to device of different orientation.
wAny-hAny Size Class - For all device to display view in as it is in landscape or portrait. Add all required controls in this size class.
wCompact-hRegular Size Class - For all iPhones in Portrait mode only. If you have added any control in this size class it will not be displayed when application will be in landscape mode and also not in iPad either.
wAny-hCompact Size Class - For all iPhones in Landscape mode only. If you have added any control in this size class it will not be displayed when application will be in portrait mode and also not in iPad either.
Final result when displayed in device or simulator. where label is displayed only in portrait mode and is invisible in landscape mode.
Conclusion. For displaying label in landscape mode you need to add label in wAny-hAny size class and then change constraints for portrait and landscape modes. For iPad you can use wRegular-hRegular.
Hope it helps you in solving your problem.
Upvotes: 1
Reputation: 7031
It's likely your layout constraints is pushing your buttons off the screen when your screen rotates. For example if your button is set at 400 points from the top margin and you rotate your screen that has a height of 320, your button may be sitting at 400 points in the y-coordinate which is off the screen.
Try using the iOS Simulator's Debug View Hierarchy tool. Use this to check to see if the button is off the screen. If so, you'll have to edit your layout constraints.
Upvotes: 1