IOS app - how to make the main window rotate

I have a background image in my main window, so when I flip the views, this is not an empty white screen behind, but an image. My problem is that this image does not rotate when the device rotates.

Edit: As far as I can tell, Brett was right when he indicated that I would have to manually rotate the background image in this case. If this helps someone else in the future, here's how I turned it.

Inside myAppDelegate :

 - (void) application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration { if (newStatusBarOrientation == UIInterfaceOrientationPortrait) self.bgImage.transform = CGAffineTransformIdentity; else if (newStatusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) self.bgImage.transform = CGAffineTransformMakeRotation(-M_PI); else if (UIInterfaceOrientationIsLandscape(newStatusBarOrientation)) { float rotate = ((newStatusBarOrientation == UIInterfaceOrientationLandscapeLeft) ? -1:1) * (M_PI / 2.0); self.bgImage.transform = CGAffineTransformMakeRotation(rotate); self.bgImage.transform = CGAffineTransformTranslate(self.bgImage.transform, 0, -self.bgImage.frame.origin.y); } } 
+7
source share
2 answers

I think UIWindow passes rotation events to child controllers. The window should contain the view of the root view controller, and then pass the rotation event message to the view controller to control the rotation.

You should be able to listen to these events in your application and control the rotation of the image manually. Otherwise, just add an image as a subview of the root view controller.

+7
source

On your root controller, make sure that you implement this method:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return YES; } 

You, the rootViewController, are probably just plain UIVIew with two UIViews, one for the background image and the other for your main interface.

0
source

All Articles