0

Possible Duplicate:
Orientation in a UIView added to a UIWindow

When I am adding my loading view as subview using [[[UIApplication sharedApplication] keyWindow] addSubview:myView.view] (so that it comes on the top of all the views) the orientation of the view is showing in portrait even though my app is locked to landscape. When I add directly as add subview this doesn't happen.

Any idea why where I am going wrong?

Community
  • 1
  • 1
pa12
  • 1,493
  • 4
  • 19
  • 40
  • Related question: http://stackoverflow.com/questions/2508630/orientation-in-a-uiview-added-to-a-uiwindow – Felix Sep 09 '12 at 21:45
  • This is a strange construct, adding a a view as a subview of the `keyWindow`, and bound to not receive notification events. Why not add as a subview of your view controller's view (in which case the view controller will be getting all of the appropriate rotation notification events). You can work around your construct, but why do it at all? – Rob Sep 10 '12 at 01:55

2 Answers2

0

Without the code it's hard to tell, but it's probably because when you add a subview directly to the window, it is not a subview of your root view controller's view,and does get orientation notifications. I would either avoid adding it to the window's subview directly, or if you must, register for orientation notifications like so:

[[NSNotificationCenter defaultCenter] addObserver:myView
                                         selector:@selector(orientationChanged:)
                                             name:UIDeviceOrientationDidChangeNotification
                                            object:nil];  

and then add the appropriate methods to your myView view controller to handle it.

deleterOfWorlds
  • 552
  • 5
  • 9
  • My app is fixed to landscape mode then how does it matter?This issue even when the device is not rotated. – pa12 Sep 09 '12 at 23:18
0

Also guessing in the absence of code, but another theory is that the ViewController that owns the view responds to - (BOOL)shouldAutorotateToInterfaceOrientation: with a true value only for portrait (I think much of the xcode-supplied template vc code does this by default).

From the little bit of code offered, maybe the ViewController we're talking about is called myView (if I'm right about that, "myView" is a poor name choice for an instance of a ViewController). Check that ViewController's implementation of shouldAutorotate... make sure it answers YES when the to-be orientation is landscape.

danh
  • 62,181
  • 10
  • 95
  • 136