How to rotate the ipad screen using code in my ios app
When my app is launched, it is initially in portrait orientation. It can rotate when the ipad device is physically rotated.
I hope to add a function that allows users to click a button to open a help tutorial. I want the tutorial to only be landscape.
So I override the shouldAutorotateToInterfaceOrientation method to check if the app is in help tutorial mode; returning 'Yes' if it is:
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==UIInterfaceOrientationLandscapeRight)`
When the screen is in portrait, and the user clicks the button to open the help tutorial, how do I rotate the screen to landscape at the beginning of my button response code?
If the controller with the help tutorial doesn't support Portrait, it will automatically show the image in Landscape mode, even if the user doesn't hold the device like that, you shouldn't need to "rotate" the screen yourself, through code.
If you want to rotate your view manually (but NOT change the device orientation), use this code for a 90 degrees rotation
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI_2); self.view.transform = transform;
M_PI_2 = 90 degrees
M_PI = 180 degrees