Hide of tabbar shows whitespace (even if frame is fullscreen) - iphone

Trying to make fullscreen view in a tabbarcontroller. It's in landscape. Are able to hide the tabbar with self.tabBarController.tabBar.hidden = YES this leaves a whitespace where the tabbar have been.
Making the tabbarcontroller's view fullscreen with:
self.tabBarController.view.frame = self.view.frame = CGRectMake(0, 0, 480, 320);
[self.tabBarController.view setCenter:CGPointMake(160.0f, 240.0f)];
self.tabBarController.tabBar.hidden = YES;
self.tabBarController.view.backgroundColor = [UIColor redColor];
Then I try to make the viewcontrollers view fullscreen also. But it will not stick, unable to resize view.frame.
self.view.backgroundColor = [UIColor yellowColor];
self.view.frame = CGRectMake(0, 0, 480, 320);
[self.view setCenter:CGPointMake(160.0f, 240.0f)];
Is there anyway to get around this in a nice fashion?!
Image of whitespace (in red) were tabbar is gone

Set hidesBottomBarWhenPushed property to YES before pushing your viewController.

Did you try to play with autoresizingMask property of your view controllers instead of trying to resize manually the view frames ?
self.tabBarController.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
self.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);

Related

shouldAutorotateToInterfaceOrientation UIToolbar in landscape mode is one pixel off

I do add a Toolbar to my view like this:
self.myToolbar = [UIToolbar new];
self.myToolbar.barStyle = UIBarStyleDefault;
self.myToolbar.tintColor = [UIColor BAR_COLOR];
self.myToolbar.frame = CGRectMake(0, self.view.bounds.size.height-44, 320, 44);
self.myToolbar.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
[self.view addSubview:myToolbar];
In the interface builder I set fixed to top and left margin for the view.
Also in the simulated metrics I set Status Bar to Black, Top Bar to Navigation Bar and Bottom Bar to None.
This works perfect in portrait mode. And looks like this:
Now when I rotate to landscapemode the toolbar gets resized and everything BUT it is off the buttom
by one pixel like this:
What could be the cause off this?
The following code is working :
self.myToolbar = [UIToolbar new];
self.myToolbar.barStyle = UIBarStyleDefault;
self.myToolbar.tintColor = [UIColor BAR_COLOR];
CGRect screenRect = [[UIScreen mainScreen] applicationFrame]; //get the rect of the screen
self.myToolbar.frame = CGRectMake(screenRect.origin.x, screenRect.size.height-44, screenRect.size.width, 44);
self.myToolbar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:myToolbar];
EDIT
It is actually a bug occuring on the iOS5 simulator.

view inside scrollView it is not moving

I have a UIScrollView of size 320x412 and inside it an UIView of size 280x277.But I tried for hours to make that View move up and down when I drag it.If I replace the UIView with a TextView it is working...I can drag the TextView up and down inside the UIScrollView...but with the View it is not working.
This is how my xib file looks like.The black one is the View I want to make it move inside the UIScrolView.ANy idea why is this not working?
EDIT: I did this
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
scrollView.contentSize = CGSizeMake(320,480);
scrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
scrollView.bounces = YES;
scrollView.bouncesZoom = YES;
scrollView.scrollEnabled = YES;
scrollView.minimumZoomScale = 0.5;
scrollView.maximumZoomScale = 5.0;
scrollView.delegate = self;
//myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[scrollView addSubview:myView];
[myView release];
And still not working!
You need to set the content size of scrollview greater then scrollview frame height to make the scrollview to scroll vertically. You scrollview height is 412.
Set content size, scrollview.contentSize = CGSizeMake(320, 430);
ALWAYS resize scrollview.contentSize .....
and not the scrollview.frame :===////
good luck! :=)

How to display UIWebView with correct zoom scale in landscape

I create UIWebView and set autorotate like this:
- (void)loadView
{
self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
webview.delegate = self;
webview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_darkgreen_320x312.png"]];
webview.dataDetectorTypes = UIDataDetectorTypeLink;
webview.multipleTouchEnabled = YES;
webview.scalesPageToFit = YES;
webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[webview loadHTMLString:#"<meta name=\"viewport\" content=\"width=320\">content ..." baseURL:nil];
[self.view addSubview:webview];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
It works perfectly when I rotate it in landscape without zooming. It will display full screen on both rotation.
The problem is if I zoom-out or a little bit zoom-in in portrait mode and then rotate it in landscape, webview still zoom with the same size of portrait mode and it has black space like in picture > http://cl.ly/1o3c4712053C3T2C2H2z
It's width in landscape is correct, 480px (you can see its scrollbar is on most right of screen). I don't understand why webview don't display full screen.
What I do wrong?
Is there any way to fix this?
Please help.
Thanks in advance.
In order to achieve your effect you need to set the zoomScale to 0 on rotation. See my full answer here: UIWebView content not adjusted to new frame after rotation

UIWebView frame to fill screen when loaded landscape and portrait

I am adding a UIWebView to my view, which works fine when I am in portrait. But when I load that same UIWebView in landscape it does not fill the screen. I suspect it comes from how I am setting the frame:
CGRect screen = [[UIScreen mainScreen] bounds];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
webView.scalesPageToFit = YES;
Is there a better way to do this so it will load correctly in both landscape and portrait, and fill the screen when rotated?
How sure are you that the parent view is resizing to the full width? UIWebView subview will not go larger than it's parent...
I had same problem.. After i Logged the self.view.frame.size.width i was surprised to find out thats it was 320 instead of 480. The solution to this was :
- (void)viewWillAppear:(BOOL)animated {
[self.view setBounds:CGRectMake(0.f, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self.view setCenter:CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2)];
[(UIWebView*)myWebView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];}
Seems that the correct size of self.frame is returned just before showing the view :)

Landscape Screen shifted to right in 20px

I am trying to rotate the screen on the iphone. For example,
First state of screen : is "Portrait".
Then it calls "Landscape" screen. Following code is used for making Landscape screen :
- (void)viewDidLoad {
[super viewDidLoad];
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGFloat angle = 90 * M_PI / 180;
self.view.transform = CGAffineTransformMakeRotation(angle);
self.view.center = [nRangeAppDelegate sharedAppDelegate].window.center;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 480, 44)];
label.textAlignment = UITextAlignmentLeft;
label.numberOfLines = 2;
label.text = #"12345\n67890";
[self.view addSubview:label];
}
But above code shifted to right in 20 px.
How to make 480x320 view at point 0,0 no shifting ?
Thanks in advance.
Update:
My application navigation based application. All UIViewControllers have one UIView. When call the the view I am trying rotate, this code is used : MyRoratedController *myCtrlr = [[MyRoratedController alloc] initWithNibName:#"MyRoratedController" bundle:nil]; [navigationController pushViewController: myCtrlr animated:NO]; I've changed CGPointMake(160.0, 240.0) by many different values. But no changes.
Your window is shifted because the appDelegate window is not centred on the screen as it is drawn below the status bar
Try this:
self.view.center = CGPointMake(160.0, 240.0);
You must make sure you are adding this view to a normal viewcontroller (ie not a nav controller or similar). The easiest way to do this is to add it to the main application window, like so:
MyRoratedController *myCtrlr = [[MyRoratedController alloc]
initWithNibName:#"MyRoratedController" bundle:nil];
[window addSubview:[myCtrlr view]];
Note that if your app has a status bar shown you will have to change the 160 above to 150