Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

UIToolbar lost in rotation to landscape

turbolagturbolag Posts: 32Registered Users
edited August 2011 in iPhone SDK Development
I am writing an app with navigationBar, tableView, and toolBar programatically. I want the app to work in landscape and portrait mode. Below is my loadView method:

	//Add the table view			//initWithFrame:CGRectMake(0.0f, 44.0f, 320.0f, 436.0f) ];
UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.delegate = self;
tableView.dataSource = self;

self.view = tableView;
//[self.navigationController.view addSubview:tableView];

[tableView release];

//Initialize the toolbar
toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;

//Set the toolbar to fit the width of the app.
[toolbar sizeToFit];

//Caclulate the height of the toolbar
CGFloat toolbarHeight = [toolbar frame].size.height;

//Get the bounds of the parent view
CGRect rootViewBounds = self.parentViewController.view.bounds;

//Get the height of the parent view.
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);

//Get the width of the parent view,
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);

//Create a rectangle for the toolbar
CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);

//Reposition and resize the receiver
[toolbar setFrame:rectArea];

//Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];


The problems are twofold:
1. The toolbar is pushed off the screen when in landscape mode
2. The toolbar covers the last row of the tableview in portrait

If I hardcode the frame of the tableview, it does not rotate properly. If I add the tableview as a subview to the navigationController.view, I see two tableviews overlaid in landscape mode.

How can I get both the tableview and toolbar to rotate and scale properly? Thanks in advance.
Post edited by turbolag on

Replies

  • turbolagturbolag Posts: 32Registered Users
    edited February 2009
    OK, I addressed the transitions from and to landscape by implementing the following method:

    - (void) willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    duration:(NSTimeInterval)duration{

    UIInterfaceOrientation toInterfaceOrientation = self.interfaceOrientation;


    if (toInterfaceOrientation == UIInterfaceOrientationPortrait){
    self.tableView.frame = CGRectMake(0.0, 0.0, 320.0, 372.0);
    toolbar.frame = CGRectMake(0.0, 480.0-64.0, 320.0, 44.0);
    //NSLog(@\"Portrait\");
    }
    else {//(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft||UIInterfaceOrientationLandscapeRight){
    self.tableView.frame = CGRectMake(0.0, 0.0, 480.0, 236.0);
    toolbar.frame = CGRectMake(0.0, 268.0, 480.0, 32.0);
    //NSLog(@\"Landscape\");
    }
    }


    This successfully positions the toolbar and tableview so they dont overlap. However, at startup the toolbar covers the last cell in the tableview, but when I transitition to landscape, then back to portrait, it is corrected!

    I have changed the frame of the tableview in loadview to CGRectMake(0.0, 0.0, 480.0, 236.0), but it doesnt help. How could I correct this?
  • anils_dasanils_das Posts: 51Registered Users
    edited January 2011
    I am facing the same problem. Did you get any solution for this?
    anil
  • farshadtxfarshadtx Posts: 2New Users
    edited August 2011
Sign In or Register to comment.