Xcode 5 - Switched to Landscape orientation, content not centered anymore - ios

I switched to landscape orientation and I have a button and slider in my very simple app. In the live view in Xcode, the content is exactly in the middle of the screen (snapped into place). However when I run the app, the content is slightly shifted to the right in the Simulator. Anybody have any idea how to fix this?
http://imgur.com/vfdO6N8
http://imgur.com/vS816p2

If you're using auto-layout try to add Constraint like this.
Click the issues Button
Then click on 'Reset to suggested constraints in Window'.

Related

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!

Horizontal slider disappears when using constraints in Xcode Swift 3

I have a horizontal slider that appears and works fine. But when I add any constraint, it disappears from the build. I've also done an archive and tried it on my real iPhone 5c device.
Any ideas what could be causing this and how to fix it?
Screen in Xcode, showing constraints:
Screen in preview (same on real device), and it does not appear:
It looks like you haven't set the y position of the slider view. You need to hook that up too, that should fix it.
On the left side of the storyboard, there is the overview of your ViewControllers. In the upper right hand corner of the one, you're currently in, there should be a tiny warning symbol:
If you click on it, you will be presented with what might be the issue:

XCode 8 autolayout preview shows a broken UI while it is working well on phones

I'm using XCode 8 and storyboard to make my UI but I am experiencing some strange issues with autolayout.
In fact, I tried something simple : centering a UILabel in my UI :
It looks good here. And to preserve the UI design, I added two constraints, like this :
with another one for the spacing between the UILabel and the "Sign In" button.
And when I build this view in an iPhone 7, iPad etc, it looks pretty good. However, when I switch the phones in the storyboard, the UILabel is moved and it doesn't look good :
So my question is : is there an issue with the preview in XCode 8? Or is it just a normal behaviour?
Thanks!
The orange labels in the preview mean that the label is not in its final location. You can force xcode to refresh by clicking the update frames button at the bottom of the screen, next to the constraints tie-fighter icon.

Why is iOS simulator displaying blank screen when I rotate device?

Getting through some introductory swift and playing with Xcode and I basically just have a page with some color squares, background color etc. Doesn't do anything. Problem is when I compile the code it will run in simulator just fine and show everything perfect, BUT when I rotate the device, everything disappears and it only gives me a blank white screen. Rotating right or left does it. The only view that shows it is the original upright view (for all iPhone devices that I tested on through the simulator).
Xcode 6.1.1 and iOS Simulator 8.1 are being used on my MacBook Air with OSX 10.9.5.
In the App general page, I have already checked under Deployment info that Landscape Right and Left are both checked on. Storyboard is set on Any H and Any W.
I'm not sure what I'm doing wrong and it has been pretty difficult searching since I'm still new to iOS development I'm not sure I'm using the right words or whatever because I can't find an answer.
Summary:
App displays properly in iOS Simulator, Portrait View but no other views work and will display blank white screen instead.
In order to see if your views are actually being drawn and just off screen as others have suggested capture the view hierarchy. Go to 'debug' in the menu, then in 'view debugging' click capture view hierarchy. This will pause your app and create a 3D representation of all view on your screen which you can move around by clicking and dragging.
Are your views actually being drawn? If yes are they drawing off screen? If yes then you need to fix your constraints.
It sounds like you haven't set your constraints appropriately. Try setting the top and leading constraints for each of your views to something less than 320 (should cover all device sizes). Fix your warnings, then try again. I believe the views are simply off the screen.
You don't have the correct auto-layout UIConstraints set in interface builder. Check the document outline view in interface builder and ensure that you have appropriate constraints set on each view.
Auto Layout issues occur when you create conflicting constraints, when you don’t provide enough constraints, or when the final layout contains a set of constraints that are ambiguous.
Check this Apple documentation out, it will show you step by step how to resolve your (common) issue.

portrait layout wont scroll in landscape orientation

Im quite new to XCode and Interface Builder, so forgive me if the solution is obvious.
I have designed a nice portrait IPhone view in interface builder (XCode 5) and have set the constraints on each of the elements (labels, text views, switches, buttons etc) so that they are positioned correctly in either 3.5 or 4 inch portait mode in the simulator.
However, when I rotate the simulator to landscape it breaks the design with elements overlaying each other and other elements disappearing (being clipped from the view) - and I expected this.
My idea of a solution is to put all of the UI elements inside a UIScrollView and set constraints on the scroll view so that it fills the screen in either portait of landscape mode.
After doing this, the portrait view is as before in the simulator, but in landscape view nothing scrolls, and none of my UI elements respect their constraints (stretch horizontally etc). Im still losing UI at the bottom and I cant scroll it into view.
I assumed that putting everything into the scroll view would simply 'fix' this issue, but the scroll view seems to do absolutely nothing at all. I have fiddled with various settings in interface builder but nothing fixes this.
There seem to be lots of long-winded solutions to this type of scenario based on code, but surely something this simple and common should just 'work'
What am I missing, or what have I done wrong, or does simple scrolling really have to be extensively coded in order to work ???
Putting all of your elements inside a scroll view won't really solve anything. Those elements would still need constraints to know how to position themselves in the scroll view. You need to be careful as well, as this solution sounds like something that goes against apples human interface guidelines. I'd advise against ignoring those, as Apple are known to reject apps that do this.
I'd say your problem is your constraints simply aren't setup correctly if elements are cover other elements and moving into the wrong places when rotated.
Annoyingly the WWDC videos section of the developer site is still down, but when it's back up, have a watch of the video of autolayout in Xcode 5, it will help explain what's going on.
If you want elements to completely change position when rotated however, you're likely to need more than just constraints, and would need to throw in some code to handle the transition between portrait and landscape. So it really depends on what the view is supposed to do when you rotate the device
OK, Ive figured it out. It IS a bug in either XCode 5 or IOS 7
I created 2 simple iphone UI's in interface builder - one in Xcode 4.6.3 targeting IOS 6.1 and the other in XCode 5 Beta 4 targeting IOS 7 beta 4.
The first app ran entirely as I had assumed, with the scroll view scrolling in landscape mode. The second app had no scrolling at all in the scroll view - so obviously a bug.

Resources