I have a problem with rotating a subview when the device orientation is changed. My situation is:
I have root view controller that is declared in
//in AppDelegate.h
@property MainViewController * myMainViewController;
//in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.myMainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
CGRect initFrame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
self.window = [[UIWindow alloc] initWithFrame:initFrame];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
self.window.rootViewController = self.myMainViewController;
return YES;
}
In root view controller, I add a subview programmatically; the initial device orientation is portrait, and the size of my subview is set with frame property value (0, 0, 300, 600).
//in MainViewController.h
@property ContentViewController * mySubViewController;
//in MainViewController.m
-(void)viewDidAppear:(BOOL)animated
{
self.mySubViewController = [[ContentViewController alloc] initWithNibName:@"ContentViewController" bundle:nil];
[self.mySubViewController.view setFrame:CGRectMake(0, 0, 300, 600)];
[self.view addSubview:self.mySubViewController.view];
}
When then device orientation changes, I would like to resize my subview according to the new device orientation. If this is landscape, then I want to set my subview size to (0, 0, 600, 300).
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if(fromInterfaceOrientation==UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
self.mySubViewController.view.frame = CGRectMake(0, 0, 300, 600);
}
else
{
self.mySubViewController.view.frame = CGRectMake(0, 0, 600, 300);
}
}
But, the result is not what I expect. The size of my subview is a rectangle with a size of about (0, 0, 300, 300). What is the problem?