Changing simulated matrics screws up layouts in xcode - ios

I built a nice fancy layout for iPhone and then decided I should try make it look a little better on the iPad. So, I changed some of the constraints (as I should have) and changed the Simulated Matrics to "iPad Full Screen". Things seemed OK until this point. However, when I changed back to iPhone, some controls were lost off screen, in the wrong place and some seem to have totally vanished. It's also not doing things like transforming a progress bar I use, but it used to.
One note: I started out with support for only iPhone. I went and changed that setting in my projects options and it said to me it was going to create a "Main-iPad"... I cant find this file anywhere.
1/ How do I recover the controls which have gone far outside the view
controller?
2/ Is there something I'm missing here? Each time I change the
simulated matrics, it screws up the other devices layout.
3/ Has the new "Main-iPad" storyboard file been hidden somewhere? Or
integrated into the "Main" file I currently have?
PS> 1st app and rather new to Xcode...
Thanks

To recover the controls you can go to the "document outline" in the project interface and find your object there. Then go to the size inspector an set the X and Y to 0, so the control will be reset to the top left corner.

Related

I have to update frame of everything in storyboard every time I start Xcode

So each time I open my project in Xcode, I have 100's of warning because the frames of every UI Object has been moved. I have to take the time and go to each UIViewController and update frames on it.
Is there a reason this happens? How can I fix this? Any other information I need to mention?.
Do you use a repository for your code? There may be some configuration file missing, probably not comited properly
In my case, this was happening because size-class for which I have set the constraints and layout got changed when I opens the Xcode project. So make sure that the size class remain the same for which you have applied the layout or change it if it has been modified by the Xcode.
If above does not work for you, you can try having a local repository created by the Xcode and commit the code before you quit the Xcode.
Hope this helps!!
I believe this was asked previously here:
Interface Builder degrades storyboards, resizes and repositions views in small increments
I have not yet seen a fix to the problem, but the answer I posted there likely holds true here.
https://stackoverflow.com/a/28577800/682574
At least one source is due to storyboards resolving layouts to either full pixel boundaries (x=7.0, y=10.0) or partial boundaries (x=7.5, y=10.5). As best I can tell, this can be recalculated any time you view the storyboard and the rounding is actually determined based on the current display environment.
You can intentionally cause this behavior by viewing the storyboard on a retina display and then viewing it on a non-retina display. With my dual-monitor display, if I just drag a storyboard from one screen (retina 5k) to another (non-retina) it will generate a flood of misaligned constraints. Unfortunately moving it back doesn't fix them! Try it out for yourself (or don't ... it's a pain to correct).
In a team environment its easy to see how this could happen as soon as two people with different setups view the same storyboard.
How to fix it? I haven't heard of a workflow that properly corrects or avoids the problem unfortunately.
Here are a couple of reasons I've seen for intermittently misplaced views. I'm not sure if either of these is responsible for the problem you're seeing -- usually these will cause a few views to be misplaced here and there, not every view in your storyboard. But I've listed them just in case it helps.
Different team members may be using different versions of Xcode, which may position certain views slightly differently, and which will certainly change the storyboard file "tool version" and so forth.
Constraints are not usually happy with fractional widths/heights in them. This can be difficult to detect -- for example, you may have a view whose intrinsic height is an odd number of pixels vertically centered within a view whose height is an even number of pixels, causing the inner view to start at a half-pixel offset and want to be repositioned lower or higher when the storyboard is re-opened.
For xib files, you can easily write a script that updates automatically the frames:
ibtool input.xib --update-frames --write input.xib
But, you should not worry about these warnings: the frames will be automatically adjusted during the execution.
Its could happens due to having 4k external display. Everybody in my team does not have this kind of problem, only me.
After opening Xcode tries to align logical points to physical pixels, so everything moves about 0.5 point.

Xcode 6: label won't drag

Im just picking up ios development, and Im having a stupidly basic problem with xcode...
I open up a new app and open main.storyboard, and drag in a label to the center of the panel:
It just sticks to the right side, and no matter how many times I click on the darned thing, it won't move! I closed the project and started a new one, and that one worked just fine, but the problem keeps appearing just about every other time I open a new project. why does this keep happening?
That is a strange problem. You say that if you close the project and start it again, it fixes itself but keeps reappearing.
Few suggestions, try clearing up some ram by closing other, unused apps.
If that does not work, I would say delete Xcode, restart your mac, and start over. Maybe something went wrong during the install.
Storyboards are scrollable and when you scrolled out your views, you cannot make any changes to the views. Try scrolling into the storyboard and then retry moving the label.
It's AutoLayout, which is the highly recommended default for laying out components now. You need to create constraints to
position it, using the icons below the layout area.
Some components I've found I need to manipulate via the size inspector, before constraints are applied.
You will need to read up on Auto Layout sooner or later. It may seem like a hassle or drag at first, and a lot of people are cursing when they have to switch to the paradigm, but when you start to master it, it is very powerful. And it really is a sensible way to handle the layout across all the new screen sizes and orientations. It developed out of a need to manage that complexity to keep apps looking good.
Icons in IB where you set constraints for selected views:
Apple has good documentation for how to use Auto Layout as do many bloggers and sites. You will have to put some hours into getting used to it, but in a day or two you should start seeing good results.
(and don't blame me, I'm just the messenger)

iPhone App not showing up properly on iphone 6 simulator

My app works good on iphone 4s, 5 , 5s simulators. On iphone 6,it shows up weirdly. It does not occupy the entire screen
What could be the issues?
if you are using the Auto resizing just under stand the concept for example
assume that u have a book self , u need to layout the book in the book self so u need to do the following steps
initially arrange the book self (this is your main View).
arrange the all books in inside the book self where u need the location (this is your subview, buttons, labels, all UI Elements).
u keep to follow the above two steps in always. got it
need reference follow the apple tutorial
this tutorial may also help u
The black view is an added view? If the goal is just to set the background color, better to just set the color of the root view.
If you're not using autoLayout (and I don't reccomend it, it's more trouble than it's worth in most cases) one simple to handle different screeen sizes is programatically.
Everything in the view in Interface Builder needs to be an outlet.
in -viewDidLoad, set the center of each view. For example, to center the mobile number text: [self.enterYourMobileNumberLabel setCenter: CGMakePoint(self.view.center.x, self.enterYourMobileNumberLabel.center.y)]
You could also set the frame for more percise handling, etc., using margin constants. Frames are often more code and more cumbersome, but AutoLayout is a nightmare.
Resolved the issue. Thanks for your valuable responses users.It has got nothing to do with Autolayout or autoresizing.
Just go to images.xcassets, right clicking in the navigator area, add launchImage. Then select your project (or target), go to general-->App Icons and Launch images and set Launch Images Source as Launch Image and most importantly, set Launch Screen file blank.
The app would now work well in iphone 6 simulator too.

previewing autolayout with different sizes and language styles

I've started learning the new Auto Layout stuff in XCode on iOS. Auto Layout is actually quite neat, but it appears to be a pain to test. I seem to remember on the Mac side there was a way you could Preview an interface and drag it to different sizes to test if controls lined up properly. Is there anything like this for iOS or some tool to facilitate testing your AutoLayout views? Additionally, something to switch to Right to Left would be useful too. I just want to test all my constraints and make sure they're perfect.
To view a preview of what Auto Layout will do under different conditions, do the following in Xcode 5:
Open up a storyboard.
Open the assistant editor (as many as you want).
In the assistant editor, tap the 4th button (the one that says Manual/Automatic/etc).
Choose "Preview".
You can now use the controls on the bottom right to customize:
the iOS version (6 or 7)
device rotation (portrait or landscape)
device screen size (3.5" or 4")
To simulate a right-to-left language, according to the WWDC 2012 Auto Layout by Example (Session 232) video:
Set the following arguments: (using a method such as this)
AppleTextDirection YES
NSForceRightToLeftWritingDirection YES
More arguments that can help with Auto Layout can be found here.
If you have localized strings, you can go to the Xcode Product menu then pick Scheme ---> Edit Scheme. In the top section on the right (Arguments Passed On Launch), click the + button and then type in: -NSDoubleLocalizedStrings YES and make sure the check box next to it is checked. This will double all your localized strings to simulate a language like German that tends to have long words.
Thanks to Apple we have the live preview in the new XCode 5.
One option for iOS i've found is to set Status Bar to None on root View of the XIB. This will remove the black status bar and show resize handles. This way you can drag the frame around and see how the controls behave. It still won't run code though. Also, I haven't found out how to enable Right-To-Left text yet.

Why does the iOS Simulator show only a blank view/window?

I'm new to iOS development. I used the Interface Builder to add text fields and buttons to my view. When I run the app, the iOS Simulator only shows an empty beige screen. What am I missing? The console doesn't show any error.
It is because you have not connected your view to your File's Owner.
To do this Right Click on the View, Control Click on the Oultlet of your View and drag it to the File Owner.
This shall solve your problem.
Cheers
I reckon it's because you have AutoLayout turned on in your storyboard, but haven't set any constraints.
Follow my instructions in the following article, to confirm if this is true.
AutoLayout problem
Basically, with XCode 6, if you have AutoLayout turned on, you must set constraints on every single control... otherwise your screens will look fine within XCode, but the controls in your screen could (and will) end up anywhere and in any size when the app is run.
It's like designing a beautiful webpage, then displaying it in an angry, drunk, disorientated browser.
XCode is really unintuitive, and unhelpful for beginners... but once you learn the rules of AutoLayout (along with its many quirks), it's reasonable useful.

Resources