Anju
Anju

Reputation: 524

How to manage orientation in iPad app

I have added a image on navigationcontroller in appdelagte class. and set yes in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    loginViewController = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];

    [self.window addSubview:_navController.view];

    _navController.navigationBarHidden = NO;
    navimage = [[UIImageView alloc] init];
    navimage.frame = CGRectMake(300, 18, 177, 47);

    navimage.image = [UIImage imageNamed: @"logo.png"];  

    [_navController.view addSubview:navimage];
    [self.window makeKeyAndVisible];
    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}  

But navigation image position is not changing. The frame remains same in both modes.

Please give me idea how it will be solved in the case of navigation controller image.

Upvotes: 1

Views: 158

Answers (2)

mChopsey
mChopsey

Reputation: 548

You should add this in your controllers viewDidLoad method and shouldAutorotateToInterfaceOrientation in your controller.

-(void)viewDidLoad{
 navimage = [[UIImageView alloc] init];
 navimage.frame = CGRectMake(300, 18, 177, 47);

 navimage.image = [UIImage imageNamed: @"logo.png"];  

 [_navController.view addSubview:navimage];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
 return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}

Upvotes: 1

demon9733
demon9733

Reputation: 854

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
}

The code above should be written in the UIViewController class (LoginViewController in your case), but not in AppDelegate.

And if you need only portrait orientations, use this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}

Upvotes: 1

Related Questions