GUI elements position in Xcode Storyboard differs from their position in the simulator - iphone

I recently worked with Xcode, especially with layout GUI elements. I read a lot of questions here about this, but it did not help me. What I have: ViewController, it lies ImageView, it lay all the other elements, I disable autolayout, screen size and in the simulator and in Xcode - the same (4 inches), but when I run I still see it:
What am I doing wrong, what is there is a way to what looks like a storyboard, and looked in the simulator (and real device) equally?

There might be two issues you are suffering with, please check following points for better understanding.
Check this with iOS 6 simulator. If its working fine then, you need to set ios 6/7 deltas for your subviews. Here is better explanation of it-- Interface Builder: What are the UIView's Layout iOS 6/7 Deltas for?
Check autoresizing masks of your subviews, definitely this is what affecting your views.
Good Luck!

Notice that in your Storyboard view, you have not displayed a status bar and that when running on the simulator, a status bar is shown. This is why all the objects are off placed. To fix this, you can either:
Hide the Status Bar - Call this method in your desired view controller:
- (BOOL)prefersStatusBarHidden {
return YES;
}
Show a simulated metric - Switch on the status bar simulated metric in your Storyboard:

Related

iOS7 issue with container view

EDIT**: Although someone has decided they would like to down vote without a reason I'm going to leave this up. I noticed that in viewDidLoad of my view controller container, the content view I setup was the same size as in IB. When I later tried to load other views with my view container controller, the content view had changed it's bounds. Hope this helps anyone else that has a similar issue. The excepted answer worked. Since this is a build for iOS 6 a simple check of OS version made this an easy fix.
I have a strange issue that seems to be iOS7 related. This is an iOS6 targeted app. I have followed apples own docs about creating custom container views here. The problem I'm seeing in iOS7 is the first view I load is within the proper bounds of the content view i have defined, the other two are filling the bounds of the entire screen so it hides under the navigation bar with my segmented control. I defined the view I'm loading in a separate view controller in storyboards. Is there some sort of constraint that is working against me?
I should add that I have noticed the content view I defined in my container controller is actually changing it's size after the initial view is loaded. I'm at a loss of how to stop iOS7 from changing that UIViews frame size when it really shouldn't be changing.
Here are some screenshots. Code is pretty much the same as in the apple docs, have tried a few other ideas, defining bounds etc. but I think it has something to do with IB since the content view is changing its bounds. It appears to only be doing so in iOS7.
There is actually a proper way to fix this,
Set edgesForExtendedLayout to UIRectEdgeNone for the view under the tab bar.
Of course, I might've just looked at the pictures and assumed this was your problem...sorry if its completely unrelated..
That's a known 'issue' in iOS 7. Since you can now have a blurred look through the UINavigationBars, UITabBars, ... This also causes issues in native apps (e.g. the Photos App) or APIs.

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!

How to trigger view rotation on new created view?

Simple question, hope there is a simple answer.
My scenario: iPhone app with NavigationController
Level 1: View with shouldAutoRotate..orientation=..Portrait (works)
Level 2: View with shouldAutoRotate..orientation=..Portrait (works)
When the iPhone is rotated, the views stay on portrait mode, perfect.
Level 3: View with shouldAutoRotate..TRUE (doesn't work on first load)
The first load of the view is in portrait independent of iPhone orientation and stays there, bad. After the view is ready, all rotations are recognized and work perfect.
Is there a way to tell the app "check your orientation now"? Several tricks I found didn't work (anymore) and the apple documentation seems less than helpful on this special topic.
So far the newest suggestion I found was to create a dummy view, show it and release it again, but I tried several places in the app and it didn't work. The view always gets stuck until you rotate the iphone manually. I would prefer a working example, so I can test it directly and see if it works before changing my code, but I'm also thankful for an explanation what to do if it works.
Thanks
//edit: As mentioned in one of the links this is considered a bug and not fixed by Apple, I worked around the problem replacing the NavigationController with own Controllers each with a Scrollview. Not very nice when you have all running and just need the rotation to work as expected, but works at least as expected. Thx to occulus for pointing in the right direction.
Please see this question:
Transitioning to landscape rotation within a uinavigationcontroller
Also:
UINavigationController and autorotation
So a good strategy might be to use Modal dialogs.

presentModalViewController:animated:NO displaying 20 pixel gap

I begin with a view-based app template. In the automatically created viewcontroller's xib (call it VC1), I add a button, and define in its interface/implementation:
- (IBAction)showVC2;
- (IBAction)showVC2 {
[self presentModalViewController:[[VC2 alloc] init] animated:NO];
}
I then create VC2. In both implementations, I allow only landscape orientations. In both xibs, I set the views to landscape. In the info.plist file, I specify starting orientation as landscape right.
When I run the project in the simulator and press the button in VC1, VC2 is displayed, but a 20 pixel gap shows both on the lower edge and on the right edge. Notably, rotation causes the view to be placed correctly on screen after rotation completes.
This issue is similar to others:
1 2 3, though the solutions identified do not seem to work in the present case. The correct/expected behavior occurs if the modal view is presented with animation (I do not want the transition animated, however). This issue has persisted since last summer (iOS 3.1.3?). It continues with 4.3. The issue does not occur in portrait orientation.
Can anyone provide a solution or explanation for why such a simple modal viewcontroller presentation does not give the expected result?
EDIT: Xcode project
I just tried building what you suggested and have no problems with a gap. I don't know if there is a way for you to post all of your code or your project. If you can do that I will try and help.

upgrade to universal app - size of mainWindow-iPad is 320x480

I have the following problem.
I have an iPhone app and want to upgrade to universal
When I do this, I get the expected MainWindow-iPad.xib.
But the size of the window is hardcoded to 320x480.
Also, there is no view in the window.
I red, this should be automatically iPad-sized, so I am assuming I am doing something wrong.
What exactly am I missing ?
thanks in advance
Yes, the dimensions of a UIWindow object are hard-coded to the size of the iPhone screen. This confused me, too, until I realized there was an option to resize it: select the UIWindow object in the .xib in Interface Builder... in the Attributes pane, make sure the "Full Screen at Launch" checkbox is checked.
As St3fan says you'll probably want to have a specific main window .xib for your iPad build.
See my answer at:
UITabBar unresponsive on iPad
I got this. I fixed it by deleting the automatically created ipad xib, then opening the original xib in interface builder and choosing convert to iPad from the menu. Then ni saved it with the -iPad name and added it to the corredt target.
You will probably also need to create a MainWindow-iphone.xib and MainWindow-ipad.xib.
I had a similar issue with a GLES application - using EAGLView, in a manner similar to all of the samples, but wanting to support iphone3,iphone4,and ipad.
in my context creation from [EAGLView initWithCoder], I was forcing the eaglLayer's rect to match the main screen, which worked for iphone and iphone4 (i.e. gave me a 320x480 or 640x960 gl surface), but for ipad, this gave me a 768x1024 surface which was cropped on present to 640x960.
As it turns out, The "Full Screen at Launch" option seems to be applied AFTER the view's (EAGLView, in my case) initWithCoder.
My solution was to do nothing in the [EAGLView initWithCoder], and only actually initialize my view after the AppDelegate's didFinishLaunchingWithOptions gets called, in the layoutSubviews call.
HTH,
forks