tags:

views:

129

answers:

5

hi all,

I am new to iphone development..

am creating one small application where two viewcontrollers like

  1. loginController
  2. updateController

For apply orientation i created two views for each controller like for first controller these are 'landscapeLoginView' & '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?

A: 

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.

TheSquad
A: 

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.

Michael
A: 

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:

Gauloises
+1  A: 

hey really thanks for agile reply.. i did this my app now,

I write all orientation code in as fallows

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation duration:(NSTimeInterval)duration {
TestAppDelegate *testDelegate = (TestAppDelegate *)[[UIApplication sharedApplication] delegate];

if(testDelegate.isLogin) {
    UpdateController *updateController = [[UpdateController alloc] initWithNibName:@"UpdateController" bundle:nil];
[self.view addSubview:updateController.view];
[updateController release];

} else 
{   
if(toOrientation == UIInterfaceOrientationPortrait)
{
    self.view = self.portrait;
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
    self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 480.0);
}
else if (toOrientation == UIInterfaceOrientationLandscapeLeft)
{
    self.view = self.landscape;
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
    self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);

}
else if (toOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    self.view = self.portrait;
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
    self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 480.0);

}
else if (toOrientation == UIInterfaceOrientationLandscapeRight)
{
    self.view = self.landscape;
    self.view.transform = CGAffineTransformIdentity;
    self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
    self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
}
}   

}

orientation working fine for loginController but when i click on 'Login' in landscape mode it will display 'portrait' view.

In IB i set portrait view as default view for 'view' property.

How to solve this?

vicky
A: 

hey all i solve this by using only one view and relocate all the controls according to the orientation.

vicky