UIView is shown displaced at the top of the screen - iphone

OK, hopefully a stupid question from a newbie...
I have an app that used to display fine base on XIB files created in UI Builder. The .xib still displays fine using the simulator direct from the UIB but when compiled and run, the view is displaced by 40 or 50 pixels (about 1/3 the width of a nav bar) so that I get a bar of white space at the bottom and half my title text hidden on the nav bar at the top.
I have tried fiddling with various parameters for the view and main window (eg layout wants full screen and resize view from NIB) but nothing seems to make any difference.
I tried upgrading xcode from 3 to 4 but no difference.
Any pointers gratefully received...

I don't know about your specific scenario, but layout problems usually boil down to inappropriately specified autosizing parameters.

Pure speculation:
Fiddling around in Interface Builder, in the typical template xib file, you can get two windows to draw your interface on. One of them refers to the window, the other to the view controller. You should leave the window alone. Anything you put in there is placed relative to the window, i.e. the screen. This would typically lead to what you describe.

Related

Subviews of ViewControllers shifted to the left in iOS 7 / XCode 5.0

I've got a project in XCode 5.0 that I ported from XCode 4. Most everything in XCode 5.0 makes sense, but I can't seem to figure out why some subviews of my view controllers are shifted to the left when I compile and run the app.
1.) I have a tableview inside of a view in a view controller. The containing view is freeform portrait with no status bars. It is 520 by 520 in interface builder, centered. When I compile the app, the table view isn't wide enough to fill the width of the view that contains it. The tableview appears to be shifted 30 pixels to the left.
2.) I have disabled auto layout. I hate auto layout for a number of reasons, mostly because I really like to tell Interface builder exactly where things need to go in specific screen configurations. (Please don't preach I just hate relative layout schemes and am willing to do extra work to avoid them).
Does anybody know what might cause the widths of subviews to change in XCode 5.0 ? I have temporarily set the frame manually in the code, but it's really weird because I need to specify a width that is approximately 20 - 30 pixels wider than what I originally had.
Any idea where this difference is coming from?

UIButton images look fine in IB but get stretched when displayed on app

I'm developing an Enterprise app for tracking mileage and maintenance for company vehicles. I've added graphic buttons to snazz it up a bit. The buttons look the way they're supposed to look on the XIB in IB, and on the iPhone all other UIViews look correct, but on one particular UIView the graphic images are stretched way out of proportion vertically.
The first image below shows how it's supposed to look, with the three graphics buttons at the bottom. The second image shows how it's showing on the phone. The Help button on this screen cap shows normally, but it can't be counted on to stay that way.
It also is not consistent. Calling this view at any time may show the image stretched or it may not show an image at all. It rarely shows the image normally, like the Help button looks below.
The development phone is a 4S running 6.1.3. The views are set for the Retina 3.5 screen. XCode is the latest (whatever it is).
Again, it's only on this one view that the problem shows up. There is another UIView on the same view controller that is hidden when this UIView is shown. The button graphics on the other view look fine. All of the other views and view controllers use the same graphics on the UIButton, without any problem.
In Interface Builder (Xcode) you created the view using a 4.5-inch screen height.
But the device where you are seeing the problem is a 5-inch screen. So the view is resized to fit.
And when it does that, the autolayout constraints that Interface Builder put on those subviews take over to determine what they do. Those constraints are causing the heights to change.
No need to turn Autolayout off. Autolayout can be very useful, but it seems to enjoy randomly assigning the constraint "Align Baseline to:" to UIButtons after repositioning them.
Just select the UIButton/UIImageView in question inside Storyboard, locate the constraint "Align Baseline to:", tap the gear icon and select "Promote to User Constraint", and tap once more and select "Delete". This should solve your issue.
In response to the comments here, I will answer my own question: I turned Autolayout off for this view controller, and that fixed everything. This is the first app I have written since XCode has begun development for the iPhone 5, so I wasn't aware of the Autolayout feature. I'll need to understand how it works and why it did what it did.
Thanks for all your help!

UIStepper does not move up when Navigation Bar dissapears

I am writing a IPhone App. In it there is a search bar (UISearchBar with Controller). When I select it, it gets focussed, and the navigation bar disappears, and the body gets darkened so that when I type on search bar the suggestions (search results) appear. My problem is when I select the search bar, before I type anything, I can see my original view through a tinted black body area. There I see all of my other controls (buttons, textfields) moved up (because navigation bar disappeared), but the UISteppers have not moved, which makes them misaligned.
Why is this ?
It may depend on how you have the relative alignment setup. In your Storyboard, use the Inspector (the ruler icon on the right hand side options) and see if you have set the others to be relative.
I believe this is a bug. I have noticed the same exact behavior in several apps I have worked on (both iPad and iPhone) Storyboard based apps. I have re-produced this behavior on apps with only one orientation. To re-produce, simply layout a scene and add UI elements of different types with at least one UIStepper. Then add the scene to a Nav Controller and all the UI elements will move EXCEPT for any UISteppers.

Scrolling through UIScrollView in Interface Builder for Xcode 4

This seems to me as though it would be a common problem, but I can't seem to find the answer anywhere. This question seems to address the issue, but I can't seem to get the solution to work and I'm not sure it's referring to Xcode 4.
When using Interface Builder in Xcode 4 and working with a UIScrollView, is there a way to scroll the view down in Interface Builder itself to view/add/edit controls that are out of the viewable section of the screen? I've managed to push a couple controls down using the arrow keys, but now I can't see them and therefore can't manipulate them in Interface Builder. Scrolling the view in IB would be first prize, but if there's a way to even select the controls using a drop-down menu or whatever so I can push them back up with the arrow keys, that would at least be something. Thanks.
Set the ViewController's Simulated Size to Freeform and set a very large height. E.g: 1000 and voilĂ ! You can now scroll to see all the stuff and add even more! :)
P.S: Remember to set set Fixed when you are finish to avoid problems!
Just a workaround which helps in Xcode4:
Expand the Objects Panel which resides on the left of the Interface Builder view (there is the tiny arrow at the bottom of the panel).
Drag your UIScrollView from the view hierachy and place it on the top level.
Now you can resize it to access more content (scrolling to that content did not work for me).
When you are done adding child views to the scrollview, you need to resize it back to be smaller or the same size as the parent view.
After your changes you would need to put back the scroll view where it belongs in your hierachy
I typically do the following when I want to (have to) build a long scrolling screen:
Set the size of the View Controller to Freeform
Set the height of the top level View to something very large
Arrange all the controls that I want on the View
Select all the controls
Select Editor->Embed In->Scroll View
Set the size of the View Controller back to normal (typically Inferred)
Well, there are a few different things you can do. There is a list of items in your view you can open on the left of the workspace by clicking the button that looks like a little play button on the toolbar. Double clicking any item selects it so you can use the arrow keys.
The best option is to use the layout panel (typically on the right) and enter position values manualy. Sometimes I will use this to move my scrollview up to where I can see where I'm working then move it back.
I found a solution although you have to use a Table view controller. If you define the table as static, the scroll works in interface builder when the table is bigger than the windows size. Moreover, a standard view can be added to the top and bottom of the table, these views are scrollable as well. The scroll is made once the controller is selected. I hope you find this trick useful.
I know this isn't exactly what you were looking for, but I always just drag the scroll view out of the view controller onto the "pasteboard" where you can resize it at will and see the whole thing.
Once I make my edits I simply resize it to fit it's allotted space in my view and place it back in the view controller.
set the root view to freeform and ~1000 pt height, go through the child views and set them to this height as well(including scroll view), in the viewdidload method set the height to the appropriate size.

Button has moved upwards when running app in Simulator

I have a strange problem when developing for the iPhone
There is one window (in green) and one view (in orange)
when I try to test my app it looks like this in the iPhone Simulator
you can see the view have moved upwards
is this normal? and how to solve the problem?
many thanks
You're most likely adding the view incorrectly. You could post some code and I could give you a better idea, or if you just want a quick fix, open the orange view in Interface Builder, make it 480 px tall instead of 460, show the simulated status bar and relayout your image.
In Interface Builder you can specify the simulated User interface elements. In the screenshots above you will notice in the green one you can see the status bar and the red one doesn't have it. You can turn on these elements by setting the properties of the view. Press Command-1 when you have the view selected and you will see a list of simulates ui elements you can add, these include the status bar, navigation controller bar and a few others i cant remember off the top of my head. This will allow you to position your ui elements correctly when you have these other elements on the screen.
The other issue with your view is that it is not the same height. have a look at the dimensions (cant remember exactly which one but its Command-2, 3 or 4 when you have the view selected) it should be 320x480, i reckon yours is 320x460... (20 pixels, the height of the status bar)