two views orientation problem
I am new to iphone development..
am creating one small application where two viewcontrollers like
- loginController
- updateController
For apply orientation i created two views for each controller like for first controller these are 'landscape开发者_JAVA技巧LoginView' & 'portraitLoginView' & for second these are 'landscapeUpdateView' & 'portraitUpdateView'
I define 'isLogin' variable in MainControllerDelegate file,
Code for orientation is as given below,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
TestAppDelegate *testDelegate = (TestAppDelegate *)[[UIApplication sharedApplication] delegate];
if(testDelegate.isLogin) {
UpdateController *updateController = [[UpdateController alloc] initWithNibName:@"UpdateController" bundle:nil];
[self.view addSubview:updateController.view];
[updateController release];
return YES;
} else
{
if(UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
self.view = self.portrait;
}
else if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
self.view = self.landscape;
}
return YES;
}
}
This will load the respected orientation after clicking on 'Login' button. Everything work fine for 'LoginController' like button events & all.
but, when i entered on 'UpdateConroller' and update text from TextView by clicking 'Update'button, it's updated for 'PortraitView' not for 'LandscapeView'.
In Interface Builder i set 'PortraitView' to 'view'.
How can i achive same functionality for 'LandscapeView'? Am i doing right?
You really should use the ability of UIView autoresizingMask... So you will have only one UIViewController for both portrait and landscape mode
It will be faster, and less of the headache to use.
This is not right place to perform view change. This method will just query if your application can support certain orientations. Use willRotateToInterfaceOrientation:duration:
to change your views instead. Also make sure to create and connect outlets for portrait and landscape views in your Nib.
I solved this by using only one view and relocating all the controls according to the orientation.
I'm fairly new to iPhone developement myself, but as far as I understand this, shouldAutorotateToInterfaceOrientation
is not the right place to handle your rotation. It is for defining which orientations your app can handle.
For handling the orientation issues, you should implement your rotation functions in willRotateToInterfaceOrientation:duration
.
精彩评论