Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-05-2009, 09:06 AM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 32
Default UIToolbar lost in rotation to landscape

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:

Code:
	//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.
turbolag is offline   Reply With Quote
Old 02-06-2009, 09:14 AM   #2 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 32
Default

OK, I addressed the transitions from and to landscape by implementing the following method:

Code:
- (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?
turbolag is offline   Reply With Quote
Old 01-15-2011, 08:01 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: India
Posts: 51
Send a message via Skype™ to anils_das
Default same problem

I am facing the same problem. Did you get any solution for this?
__________________
anil
anils_das is offline   Reply With Quote
Old 08-28-2011, 02:19 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 2
Default

i am facing the same too. any idea?! :-?
farshadtx is offline   Reply With Quote
Reply

Bookmarks

Tags
landscape, uitableview, uitoolbar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 249
24 members and 225 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, LEARN2MAKE, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:27 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0