Horizontal space constraint not working in iPhone 6 Plus only? - ios

So I'm porting my app to adjust for various devices (iPhone 4/4S, iPhone 5/5S, iPhone 6/6P). My app only operates in portrait mode so the constraints and such should be very easy. I have been leveraging the new Xcode 6.2 tools such as the preview tool, and inferred view controller size, so I only have one storyboard for every device. However I have set up all the necessary constraints and the app runs and looks great on all the devices, excluding the iPhone 6P. But what confuses me is that the preview for the iPhone 6P looks exactly what I want, however when I run in the simulator its not correct. Please looks at the images below to understand the problem fully.
The desired look is this: (what it looks like running on all devices except iPhone 6P)
Now what it looks like on the iPhone 6P: (as you can see the tableview is shifted (on both sides) inward.
However as seen in the storyboard, the preview shows it correctly:
This is what the constraints look like in the storyboard:
Hopefully you can understand the problem by now and hope you can offer some help, thanks in advance, feel free to ask for clarification.

As you have confirmed in the comments the issue is that you are constraining to the view margin instead of the view directly.
To stop constraining to a margin for an existing constraint, select it and in the Size inspector uncheck the Relative to marginfor the items.
When creating a new constraint by dragging with control key, holding the alt (option) key while creating constraints will toggle the margin option.
If you are creating it with the popup menu in the lower rigth just uncheck the Constrains to margin

Related

Issue with Safe Area - Fine on iPhone X, not on others

So I'm trying to update my app for the iPhone X (a little late to the game, I know), and I enabled safe area, and fixed (supposedly) all my constraints to match. It looks perfect on the iPhone X. But for some reason, on all other iPhones, it still accounts for the iPhone X's notch, despite Safe Area correctly displaying where the UI should start and end. I'm at a loss. None of the constraints in question are hard coded, I set them all to the "standard" value (or so I believe).
storyboard (first button is actually the talk bubble, which is just a static image, second is the paw print, which is an actual button)
messed up iPhone 8 (bubble and ui elements should be at very top and bottom)
Here's my storyboard file: https://ufile.io/35zvs
UPDATE: image for ercell0
You are using standard spacing for top and bottom for your Banner View with a required priority. try setting this to superView: 0 or safeArea: 0 and see if that corrects the issue for you.
The updated view:
Can you change ViewAs from iPhoneX to iPhone8, and attach an image?
Other iphones your are testing on are running iOS11 or older?
If running older versions, safe-area won't be able to help with the alignment. For pre iOS11, use the constraints you were using previously or Layout Anchors.

App resizes on deployment to iphone 6s - xcode

I have a simple single screen app with two buttons that looks great on the story board on xcode. As soon as I run the app on my iphone 6s, it resizes the screen and the buttons at the bottom disappear. It looks like the resolution has changed and the app is not meant for an iphone 6s screen.
I have already tried the following without any success:
1) Enabled "Use Auto Layout" for my View controller in the File Inspector menu(under utilities)
2) Set the deployment target to "10.3", Devices to "iPhone" and checked "portrait, landscape left and landscape right" for Device orientation under the General Settings.
Is there any other setting that I might have missed to check that is causing this scaling? I am using xcode 8.3
Edit: I recieved some great feedback in the comments section, and learnt about adding constraints. I am here adding screenshots of what my app looks like before and after adding constraints:
Here is my xcode storyboard (what I am looking to get on my iPhone 6s)
And here is a screenshot of what I have on my phone (prior to constraining)
I have tried constraining the view like so with no luck (same output on the phone):
Is there a specific set of constraints that will do the job here?
Your screenshots show that you have not set your constraints. The last screenshot shows that you have set some constraints on the root view. Like mentioned by Martin you need to have constraints for each object.
To place the button correctly at the bottom of the view, you need to draw from your button to your view (holding the ctrl-key) and then select the bottom, leading and trailing constraints.
I suggest to make a beginner tutorial in Autolayout with InterfaceBuilder.
Thank you for your great responses. Turns out the solution was a little different than just experimenting with constraints. It took me about 3 hours to figure this out, and I wanted to share the simple solution here in case someone else goes through the same thing in the future.
The problem was in the General section of the settings. Your Launch Screen File must reflect the MainStoryboard like so:
My Launch Screen File option was previously set to nothing which caused the problem. As soon as I changed it to the MainStoryboard, things look just fine.
Hope this helps someone!

Xcode 8 AutoLayout/Constraints: Changing view to fit each Iphone screen size?

I am new to Xcode, and have been trying to figure out how to use AutoLayout and constraints. Long story short, after I hit 'add missing constraints' the Iphone 7 screen looks just as I intended, but both the Iphone 7 plus and Iphone SE screens look completely screwed up. What can I do to fix this so that every screen looks like the Iphone 7?
Iphone 7
Example Iphone SE (screwed up)
add missing constrains option means: adds the constraints needed to have a nonambiguous layout. may not work well for all iOS devices, and may not work well for device's rotation changes or view size changes, so, check view's constrains in size inspector panel
for more info:check Apple's auto layout guide

Simulated Metrics size for "iPhone 5.5-inch" doesn't show the interface correctly in iPhone 6 plus device

I'm using xcode 6.1.1 version and iPhone 6 plus as testing device. I simply add a button at the right side of my xcode user interface, selecting Simulated Metrics size for iPhone 5.5-inch like this :
But when I run this on device the button goes far away from the right edge. Like this (Snap shoot from my device):
But when I select Simulated Metrics size for iPhone 4.7-inch like this :
It shows accurately in my device. Like this (Snap shoot from my device):
I tried with selecting and un selecting Auto Layout & Size Classes but do not get any clue. My device is 5.5 inch iPhone 6 plus. I even recheck it from my iPhone's packet and by IMEI Number. My question is why it is acting like iPhone 6 interface?? Is it for any reason of retina display or non retina display??
Thanks a lot in advanced.
My button's Constraints:
Select the button/ view you want. Then simply use the shortcut ⌥⇧⌘=. This will Reset to Suggested Constraints.
For this to work successfully, try moving your button to the suggested areas, i.e. move the button/ view to the top right corner like you have till the dotted blue lines appear.
Once done it should show what you expect on the interface builder but to be sure test on the simulator and/ or Device.
You need to add the proper constraints. Using simulated metrics is only for setting things up in IB, it has no effect on what the view looks like at run time. You should leave that setting at inferred.
If you don't add constraints yourself, the system adds them for you, and it adds top, left, height, and width constraints; that is not what you want. You need to add constraints to the top and right side. If you do that, the button will appear with that spacing to the right side, no matter what size screen you're using.
I think you should use constraints to solve the problem but i don't know the exact cause of this
Ctrl + drag from the item to the border in the storyboard to add constraints

How to make controls in view not overlap if built by Interface Builder for Xcode 4.5 and iPhone 5?

I am using Xcode 4.5 and iPhone 4 and 5 simulator, and the Interface Builder would add a UIButton in the top half of the screen with a top constraint, and add a UIButton in the bottom half of the screen with a bottom constraint.
It works fine on an iPhone 5 simulator, but on the iPhone 4 simulator, the buttons can overlap, or the bottom button may even get positioned above the top button.
I think it is due to the constraint, such as the bottom button "must be 250 points away from the bottom margin". I can't delete the constraint, and if I change it to "250 points or less", it won't work, if I change it to "250 points or more", it won't work either.
Is there a way to:
1) Make it have no constraint, but just position at absolute x and y? (or what about the spring in the past, so that everything is more spaced out in iPhone 5?)
2) Make the NIB into a one for iPhone 4 and 4S only, so that the app works well on iPhone 4 and 4S and just "black barred" on the iPhone 5.
3) Make it work well on iPhone 5 and work well on iPhone 4 as well?
If you know solutions to only (1), (2), or (3), above, please give it regardless, as it is still a viable solution for the transition period.
It is actually very easy to reproduce: Create a simple Single View app using Xcode 4.5, and drag one button just above the center point of the screen, and another one just below the center point of the screen. Then run it on the Simulator. On iPhone 5, it is:
And now stop the app, and change the Device in the Simulator to iPhone 4S (3.5 inch Retina). If you don't stop the app first, the Simulator can crash. Now run the app again, and the buttons will overlap:
I had the same problem, and it was due to a wrong settings for autosizing. To change the autosizing, click on the control in the interface builder, go to the size inspector.
Notice the bold red I's in the autosizing grid, they control placement when the screen is resized (like when going from iPhone 3GS to iPhone 5.
I think it will work best for you if you make your autosizing look like this:
I'm not sure, since I haven't used constraint-based layout (and won't until we drop support for iOS 5). Traditional NIB-based autoresizing will do absolute coordinates.
You can't do that for just one screen, as far as I know — you can disable it for your whole app by removing Default-568h#2x.png.
I'd go for programmatic layout, or if you want the easy way (which will be a pain to maintain), different nibs for different screen sizes. Note that you'll want to correctly handle the in-call status bar too...
EDIT: Put the two buttons in a container view and make the constraint center the container inside its parent? It won't adjust the spacing between buttons, but should look okay on both devices.
Select your buttons and add "vertical spacing" constraint for them. And set "less than" for top/bottom margins.

Resources