Search code examples
ipadorientationtoolbaruitoolbaruiinterfaceorientation

How to adjust the toolbar according to the ipad orientation


I added a toolbar for an ipad application programatically.

     UIToolbar *drawToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,710 , 1024, 40)];
     [self.view addSubview:drawToolBar];
     [drawToolBar release];

Now it is shown in the bottom of the ipad screen, when in the landscape mode. it comes in to the middle,when it is in the portrait mode. How can i put it, always in the bottom.


Solution

  • // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
        if((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight) )
        {
    
            UIToolbar *drawToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,708 , 1024, 40)];
     [self.view addSubview:drawToolBar];
     [drawToolBar release];
    
        }
        else if (interfaceOrientation == UIInterfaceOrientationPortrait ||  interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
        {
            UIToolbar *drawToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,964 , 768, 40)];
     [self.view addSubview:drawToolBar];
     [drawToolBar release];
    
    }
    return YES;
    }