IPhone application issue in toolbar
Here I'm using 3.2.5sdk,and 4.2 IOS,
I create on viewbased application and add the navigation based lick
UINavigationController *navigation = [[UINavigationController alloc]
initWithRootViewController:viewController];
[self.window addSubview:navigation.view];
Now i create a tool bar and set that tool bar to button and once I rotrate my mode from portrate ti landscape or vise versa lick using this code
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)willRotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
{
[toolbarview setFrame:CGRectMake(0, 979, 768, 45)];
NSLog(@"the frame size is %f,%f,%f,%f",toolbarview.frame.origin.x,
toolbarview.frame.origin.y,toolbarview.frame.size.width,
toolbarview.frame.size.height);
NSLog(@"This is protrait mode");
}
else
{
[toolbarview setFrame:CGRectMake(0, 723, 1024, 45)];
NSLog(@"the frame size is %f,%f,%f,%f",toolbarview.frame.origin.x,
toolbarview.frame.origin.y,toolbarview.frame.size.width,
toolbarview.frame.size.height);
NSLog(@"This is land mode");
}
its working fine but once i m navigate from viewController to other page and then i change my mode lick this code on second page.
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
// Overriden to allow any orientation.
if ((interfaceOrientation==UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation==UIInterfaceOrientationLands开发者_Python百科capeRight))
{
[viewController.toolbarview setFrame:CGRectMake(0, 723, 1024, 45)];
NSLog(@"the frame size is %f,%f,%f,%f",viewController.toolbarview.frame.origin.x,
viewController.toolbarview.frame.origin.y,
viewController.toolbarview.frame.size.width,
viewController.toolbarview.frame.size.height);
NSLog(@"this is the Landscape Mode in home");
}
else
{
[viewController.toolbarview setFrame:CGRectMake(0, 979, 768, 45)];
NSLog(@"the frame size is %f,%f,%f,%f",viewController.toolbarview.frame.origin.x,
viewController.toolbarview.frame.origin.y,
viewController.toolbarview.frame.size.width,
viewController.toolbarview.frame.size.height);
NSLog(@"this is the portrait mode in home");
}
return YES;
}
And according to second page mode I want to Change tool bar position but its not working .
You shouldnt need to worry about all of this code during rotation. Just place the toolbar where you want it to be (looks like at the bottom of the screen) and then just set his autoresizing mask so that it will stretch side to side and it will remain in a fixed position to the bottom.
Self.toolbar.autoresizingMask = UIViewAutoResizingFlexibleWidth | UIViewAutoResizingFlexibleTopMargin;
Then whenever your view is rotated or resized the toolbar should remain fixed to the bottom and it will shrink or grow horizontally to fit.
Or... My preference would to be to create the toolbar in your xib and set the autoresizing mask there on tab 3.
精彩评论