Why is my App always shifted to the right in the iOS Simulator? - ios

I am building a simple iOS app using Storyboards. Currently running Xcode 7.2.1. I have previously built one using .XIB files and never had an issue with layouts on devices.
I have a UIViewController that has a UINavigationBar and Bar Button Item. When I run the app in the simulator, everything looks shifted to the right and partly off screen. The title should be shown in the centre. I am simulating using iPhone 6 and everything in Simulated Metrics are set to Inferred. Could someone help me understand, am I missing a step?

The views are shifted because you didn't set the auto layout constraints. To fix this, add missing constraints.

Related

iOS app not taking up entire screen in iOS 12 or 13

I have an old iOS app last built on iOS 8. When the app runs on iOS 10 or higher on larger phones the view doesn't take up the entire screen, there is a black bar on the top and bottom of the screen. In the past, Apple would just expand the app so it was stretched a little.
Not sure how to fix this? I am sure there has to be an expand setting or something? I believe it has to do with setting a Launch Screen, but not sure where to set that or how to? I do have a LaunchScreen.storyboard in my files.
I have tried multiple things to fix the issue, but nothing seems to work?
Also, not sure if it is related, but the Navigation Item (deprecated?) was once sticking to the top and now just randomly floats.
I have solved this problem on my older project by adding launch screen.
Try this if you are missing launch screen:
Add a new launch screen by going to File -> New -> File... -> Launch
Screen
Make sure the newly added LaunchScreen.storyboard is selected as
the launch screen file under project settings.
to check this follow this steps:
1)Choose your project name in Xcode. 2)Select your project target. 3)Then select app icons and launch images and choose your newly added LaunchScreen.storyboard.
Given the age of the app I suspect it uses fixed sizes or size classes for its layout?
You will need to update the code that controls the layout. If the design is simple and vertical based, you may be able to a 'quick and dirty" solution by embedding everything in a stack view. However you should really update your code and/or storyboard to use Autolayout. This will fix the current problem and ensure it will work with future devices of different sizes.

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!

How To Fit UITableView in the screen with AutoLayout

I am trying to fill the screen with a TableView. I've tried pinning 4 edges but it broke when I view it in different devices (iPad Pro, iPhone SE, landscape and portrait orientation). The TableView is messed up for some reasons. It shouldn't be this hard to fill that in. Did I messed up some settings in my Xcode?
If you ran the application on a real device you'll find it as you expect it to be.
And if you opened another file then came back to storyboard you'll find the preview as expected too, I think it's a bug in the UI Builder.
Note: I'm using Xcode Version 8.3.2.

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.

Weird space in iOS7

I just ran a demo app on iOS 7 target, this is what I get:
I'm using a storyboard and it looks well in iOS8. Constraints are correct.
I already checked e.g.
UITableView is starting with an offset in iOS 7
but the issue in this case is the whole thing, incl. status bar has the offset, no idea what this is. I played around with the layout settings of the view controller in the storyboard without any effect.
I also created a brand new (single view) project, ran it without changing anything, got the same issue. Don't know what can go wrong in a new project concerning autolayout as I can't set any constraints in the root view controller's view...
Any ideas?
Thanks in advance.
Try adding a "Default-568h#2x.png" launch screen to keep your iOS 7 device from running the app in Letterbox mode.
What Apple really wants you to do is use Auto-layout (see point 1 in the linked blog), which is what I suspect your demo app isn't doing.

Resources