I'm so confused. I don't have a status bar, and I don't know how to make my scroll view's dimensions. Is it 320 x 480, or 320 x 460? Because when I drag it out onto storyboard and it fills the entire screen it says it is 320 x 460, but then when I add subviews to it they get positioned strangely and so that it's like the views are 20 pixels short or something.
EDIT: I'm just a little confused because when my status bar goes away, it doesn't re adjust the view size, it just makes the view 20 pix shorter, which doesn't really make sense, right? Shouldn't it make it 20 pix longer instead of just cutting off 20 pix?
The iPhone screen is 320x480 definitely.
The reason you're having an issue in storyboards is there are multiple places to tell it you don't have a status bar. You need to track down all of them (3?) and make sure it says no status bar.
The most common problem is that you have your status bar either on or inferred in one of your earlier viewControllers while you've exclusively set it to off in a nested viewController. This causes it not to have a status bar but show itself as 460 pixels high. as you can see in the image its clearly 20 pixels shorter. Thats because the segue is telling it that when its presented to present it "under" the status bar even though it doesn't have one itself. If I were to change the segue from a modal to push the problem goes away. Or if I set the first viewController to have no statusBar as well the problem goes away. Also note that Xcode can require a restart to properly update its graphical storyboard in some instances.
One More Thing
Also setting either in code or storyboards to hide the status bar isn't the same as setting the UIStatusBarHidden to YES in your .info file. If you left it to no while hiding it everywhere else your default.png will be clipped and show the status bar while loading then it will disappear once the app finishes launching. So be sure to hide it there as well for a consistent user experience.
Code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[application setStatusBarHidden:YES];
}
it is 320 x 480, the 20 pixels you are seeing is the status bar, if you are planning on hiding the status bar and want to match the size in Interface Builder, you can go to IB to Simulated Metrics -> Status Bar and select None.
This will not affect the real size of the view in your view controller, though as it will resize itself to fit in the size even if you set the view to be 320 x 480, the view controller will resize itself to 320 x 460 if there is a status bar and 320 x 418 if there is also a navigation bar.
I am a bit out of iPhone-programming, but this 20px should be the upper border, where you can see the carrier and strength etc.
Related
I' m developing an application for both Retina 3.5 and Retina 4 screens (iPhone family). And I encountered with the next problem. I create a view in .xib file and set size to Retina 3.5 full screen.At the very bottom of the screen I placed a view with UILabel. You can see the view on the screen:
As you can see the view is at the very bottom. But when I run the application either on device or the simulator view with label on some reason doesn't fit the screen:
So the question - what can be the problem? How can I fix this? Why IB view sizes is not correct?
You've set your NIB to not have a status bar, but your app does have one. This means your NIB is sized at 480 pts high (on a 3.5" screen), when it should in fact be 460 (due to the status bar). This pushes your view down by the corresponding height (20 pts, which you can see at your cut-off label at the bottom).
There are a number of fixes for this. You could just tell your NIB it has a status bar, but a better option would be to set your view to resize dynamically according to its bounds. Exactly how you do this will depend on whether you're using auto-layout or not, but you'll want to check 'autoresize subviews' and make sure your view elements stay locked where you want them to.
When updating my old program for iPhone 5's 4 inch screen, I found that the navigation controller keeps to its original 3.5 inch screen size and refuse to stretch to fit the 4 inch screen even when its view controller's view and tableview controller's view are all stretch to fit the 4 inch screen. Because the navigation controller's view is not visible during normal use, people may miss it. Because it refuses to fit the new 4 inch screen, when in landscape mode, the screen go beyond the navigation controller's view width and the right button fall off the boundary and becomes unresponsive. In order to show the situation above, I set the navigation controller's view's background color to semi-transparent red and the table view's background color to semi-transparent blue. as shown in the screen shoots below. The question is, how to fix the problem. the plus button are not responsive when in landscape mode, but in portrait mode, it works fine.
Either your navigation controller’s view or, more likely, the window that contains it, are not getting set up with the correct frame. If you’re creating the window in code, make sure you’re using UIScreen -applicationFrame or -bounds rather than a hardcoded (320, 460) or (320, 480); if you’re using a NIB, check your autoresizing masks and layout settings.
I'm working on an app and I want to make it full screen, but when I hide the status bar I get an offset of 44px (status bar size).
With status bar the buttons are on the line:
http://i55.tinypic.com/xlbjsz.png
Then I've set in the Info.plist file "Status bar is initially hidden: YES"and I get an offset: http://i55.tinypic.com/2up3ceo.png
And when I uncheck Autoresize subviews I get this:
http://i54.tinypic.com/2h821r4.png
I've put on all xibs status bar to none, including window.xib, I don't have any ideas left, please help me.
From the images you uploaded it seems everything works as it should. When you hide the status bar your view will shift up the amount of pixels that the status bar was previously using to display itself.
So if the views size is 320 x 460 when the status bar is shown (the status bar has a height of 20px so if you add that up it will make it 320 x 480 the full iPhone screen size) when you hide it your view will have a new size of 320 x 480.
As you said by default your view will autoresize the views inside and when you checked it out it's only normal to get a 20px gap at the bottom of the page.
Please keep in mind that on a retina display (iPhone 4) all these sizes are doubled, so you actually get a 40px gap at the bottom.
I'm learning to develop for iPhone (programmatically, I don't like IB). I only use IB for the frames of things, so I design in IB but only use it to check each control's frame. Something I've gotten very confused about is the frame of a UIView. First of all, if you do not implement loadView in a view controller, it automatically creates an empty UIView (and I've noticed that its black) and assigns that to self.view, correct? What about the frame? does it automatically figure out what the frame should be? I mean, it needs to be different depending on the if there is a status bar, if there's a tab bar, a toolbar, the orientation. In my tab bar app, it seems no matter what I set frame of my uiview is, it still looks fine. And also, the frames for UIView seem messed up in IB. Like the y value of a UIView taking up the whole window (except status bar) is 0, when it should be 20, because the status bar takes up the top 20 pixels. And in IB a view in a tab bar controller has a y value of 411, even though it begins right under the status bar. And whenever I NSLog a frame (the four numbers, view.frame.origin.x, view.frame... etc.) the x, y, width and height are always 0.. Can someone who understands it please explain it to me? Thanks!!
Ok, this is weird... This:
CGRect test = CGRectMake(0, 20, 320, 460);
NSLog(#"%d %d %d %d", test.origin.x, test.origin.y, CGRectGetWidth(test), CGRectGetHeight(test));
gives output:
0 0 0 1077149696
??? What's with that?
First thing you should note is that CGRect's origin and size members use float, so in your NSLog statement you need to use %f, not %d. So for example,
NSLog(#"%f %f %f %f", test.origin.x, test.origin.y, test.size.width, test.size.height);
Pixel sizes are floats because on the desktop you need precise math when doing scaling and want to support proportional sizing. If you stick to integers and the window size is expanded by, say 1.2x, integer round-off will throw things out of line. They kept the same thing on the iPhone because you can have subviews that get auto-sized and floats offer more control over size and position.
As for the view positions, if you go into IB and select a view and check the "View Attributes" inspector you'll see one of the options is to show "Simulated Interface Elements." By default it has the Status Bar enabled (with Gray) and it allows for its height in the interface. If you check the size tab in the inspector, the view height is actually set to 460 (allowing for the 20 pixel status bar).
You can choose to include a top bar or a bottom bar and it will "simulate" those by adjusting the content height for you. This is just a positioning simulation so you can lay out your controls. At runtime, it's assumed you'll load the view into the proper viewcontroller which will have the proper chrome so it should all look right.
A lot of IB numbers are there for relative positioning. When you add the view to a navcontroller or a tabview, this view becomes a child of those parent views and by default they autoresize subviews. So if you've "simulated" for that top bar in IB, your controls should all be lined up properly and flow into the right place and you should see what you expect (of course, depending on what parent control ends up with your subview as a child).
BTW, you're missing out a lot of convenience by not using IB to wire up the controls and connecting them to IBOutlets. It really helps take out a lot of manual effort and extra code. It's like Superman refusing to use his X-ray vision and instead deciding to punch through walls :-)
Answer: IB doesn't always show correct origin/location coordinates, and some things, like UITabBarController, resize the view to be what they want it to be no matter what you set it.
Ive created a multiview application that uses multiple controllers to display and control views. The problem Im having is, when the simulator initially loads the view the header is partially covered by the bar at top of screen and the tool bar at the base is not touching the base of the screen. I used the Interface builder size attributes to control the view when the iphone rotates and it works perfectly. All smaps into place perfectly both in landscape and portrait mode AFTER a rotation but the problem is with the initial load before a rotation occurs.
Your thoughts a much appreciated.
Tony
I grappled with this issue for days and days--no amount of fiddling in IB worked.
Ultimately I got it to work by adding this line:
mainViewController.view.frame = window.screen.applicationFrame;
to the application:didFinishLaunchingWithOptions: method. (Where mainViewController is the primary UIViewController).
I've had issues with views being clipped by status, nav, and tab bars. I've fixed most of them by using the Simulated Metrics feature in Interface Builder. That way what your laying out in IB is a lot more accurate to what your actually going to get.
I ran into this issue too. Specifically, when displaying an ADBannerView, my whole view would shift and be under the status bar and leave a little empty space just the size of the status bar at the bottom of the iPhone screen. Here's how I solved it : (Adam's answer here helped me figure this out):
// In the function that displays an iAD Banner
CGRect contentFrame = self.view.bounds;
CGRect myStatusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGFloat statusHeight = myStatusBarFrame.size.height;
// Set the view's origin to be under the status bar.
contentFrame.origin.y = statusHeight;
I needed to set the origin of my view to be below the Status bar, and that solved the issue for me.
The problem is that you're adding your controller "incorrectly" according to Apple docs (although IMHO Apple designed it badly - the default should be that you don't need to shift!)
if you're going to have a status bar, Apple requires that you "manually" shift all your controllers down by 20 pixels (more accurately, by the height of the statusbar - although that's always 20 pixels today, Apple lets you request the height at runtime, from the "statusBarFrame" property in UIApplication)
Apple's classes - e.g. UINavigationController / UITabBarController - automatically shift themselves down by 20 pixels when they're added to the screen. Both classes have a bug where they will do this shift even if they are not the main controller - so your app suddenly shifts down an extra 20 pixels, leaving 20 pixels of white space at top.
But, when they rotate, those classes often "get it right" and move back into place. Or vice versa.
c.f. this link for a much more detailed explanation of what's going on, and how to write your code the way Apple wants you to:
http://blog.red-glasses.com/index.php/tutorials/iphone-auto-rotation-for-intermediate-developers-tutorial-1/