I have two view Controllers added as a sub-view in the UIWindow. Now the problem is one of the view gets view rotation calls but second is not getting calls for view changing orientation. Now my problem is how we can get change orientation call for two different view controllers added in UIWindow.
Asked
Active
Viewed 424 times
2 Answers
1
UIWindow
only sends rotation messages to its rootViewController
. If you want the other view controller to receive them, you have two options:
- Write code to make your
rootViewController
send the rotation messages to the other view controller. - Implement view controller containment. Watch the Implementing UIViewController Containment video from WWDC 2011 to learn how to do this.

rob mayoff
- 375,296
- 67
- 796
- 848
-
how can i send rotation call to viewcontroller in such a way that i does not write code to rotate view(means the auto resizing property works). I donot want to rotate view using CGAffineTransform – Iqbal Khan Feb 17 '12 at 07:28
-
If you make your view a subview of your `UIWindow`, you must use `CGAffineTransform`. The `UIWindow` sets the transform of `rootViewController.view` for you. If you add other subviews to the window, you have to set their transforms yourself. – rob mayoff Feb 17 '12 at 08:01
-
You would probably find it simpler to have a single subview of your window, and make the second view controller's view a subview of that view. – rob mayoff Feb 17 '12 at 08:01
-
Actually the one viewcontroller is the Tab bar view controller and second is the ads view controller(Mobclix). Now I have added the ads just above the tab-bar so that it can be visible for all the views in the tab-bar. When i add the ad view in the UIWindow then it does not rotate with the screen but full screen add work fine. When i add ad in tabbarcontroller view then it roates but when user tap on ad in landsacpe mode. then it shows full screen ad out side the view. – Iqbal Khan Feb 17 '12 at 11:21
-
Thanks for the video link, -addChildViewController will be my solution. – Iqbal Khan Feb 18 '12 at 06:55
0
Register for device orientation.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
check in the method ,
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
}

Vignesh
- 10,205
- 2
- 35
- 73