iPhone Simulator vs. Main Storyboard Preview - ios

I have many layout constraints for a particular app, and in the main.storyboard (preview) the apps look a little bit off, but when I run them in the simulator they look how I want them. So there is disconnect between the two.
I saw the question answered that fixing the constraint warnings would then make the two appear identical.
However, I do not want to try to fix these warnings. A lot of time went into finally figuring how to lay all this out, and I'm worried fixing these (38) constraint errors will screw everything up.
My question is...with the disparity between the preview and the actual device simulation, which one will actually appear if the app is run on a real device? I would assume the one showing in simulation, but I'm really not sure. Is it safe to ignore the errors and the strange main.storyboard (preview) layout it shows me and go with the simulation? It looks how I want it for each simulated device, so I'm weary of changing anything now. Thank you!

According to my experience, Xcode has some problems in storyboard. If you have a constraint which makes a view becomes visually invisible, you will get a warning about this constraint. You can quickly fix it by clicking the warning icon BUT if you close you project and reopen it again, the warning will be there.
The final result should be the UI shown in simulator instead of interface builder or storyboard.

Related

Adding Launch Screen Removes Autosizing

Since Apple is requiring a storyboard launch screen in a few months I went ahead and tried to add one. Adding one is simple and it works just fine but it screws up the layout after loading the app. No longer does a larger screen automatically adjust the resolution, instead I'm left with an SE layout on an 8 Plus screen placed in the top-left corner with the background image repeating (like wallpaper from a 90s website). I'm not using constraints, but I'm not even sure if that's the issue. If so I have a feeling I have a lot of work ahead of me (keep in mind I've never had a need for constraints). A side thought though is, from what I understand, Apple wants all apps to look correctly on all devices... makes perfect sense. But my apps have always appeared correctly no matter the device. So it's ironic that adding the launch screen is breaking my apps' appearances. Is it the constraints? Is there an alternative solution? Or is there hopefully something simple in the launch screen that needs to be changed? Thank you!

In storyboard my views are messed up. Why is that?

I'm using Xcode 9 Version 9.1 (9B55). There is something strange happening in a storyboard. Some of my views are are messed up, and I don't know what is the reason.
It looks like this:
EDITED
However, all my constraints are set right, and when I run the project on different simulators and on a physical device, everything looks fine. Here how it looks on a simulator/physical device:
I don't know what is the reason for this kind of behaviour but it makes impossible to work in a storyboard. I think, this problem has appeared quite recently. Sometimes, after reloading the Xcode, views again look fine, but when I start working with storyboard (adding new views, changing constraints or even just tapping on a constraint to see its constant), they again become messed up. Does anybody have this kind of issue, and how this could be solved?
After closing and opening Storyboard, the issue goes away! I think it's just an issue in x-code 9.
As a quick fix, try changing the spacing on one of your stack views instead of closing and reopening Xcode. Toggling the spacing brings back the views in my case.

Autolayout works fine on iOS 8, but doesn't behave well on iOS 6 and 7 (I'm using XCode 6.2)

I'm using autolayout to correctly lay out some views inside a UICollectionViewCell. It works fine with iOS 8, but when I try to run it on iOS 7 or iOS 6, the cells appearance varies widely everytime they are laid out (sometimes I see small changes in size and positions - one or two pixels - and sometimes big changes, resulting in some pretty messed up cells).
I swear I tried hard to find anyone with the same problem, but I couldn't. I didn't find any answer that could help me solve or even get close to understanding the problem either.
I would appreciate any inputs on how to solve or even debug this better.
MORE INFO
I'm using Interface Builder to create the view and set up the constraints. The cell's view has a total of 17 subviews, including UIViews and their subviews, and they do have a great number of constraints.
I update a UIColletionView (which includes a table of my custom cells) everytime I press a button.
What I find outrageous here is that when I run the app, everytime I press the button, the cells' subviews change their positions and sizes. I never change any constraint or frame programatically.
Also, the behavior is worst on iOS6. The frames chage a lot more and autolayout runs really slow (it take 3-10 seconds to update the collection view on iPod Touch 5th Generation, even if it has only one cell).
Worst of all, if I keep updating the UICollectionView, sometimes XCode will complain of constraints not being simultaneously satisfied. But most of the time it works just fine.
I'm also running into crashes in some devices when removing some of my autolayout-enabled views from superview. I found this is a strange behavior of Autolayout engine, which could get to some bad calculations due to float errors. I'm wondering maybe this two problems are related.
As I couldn't find any help in the entire web after searching for almost an entire day, I'm starting to think this must be a stupid error with a stupid solution. I do hope so.
Thanks in advance!
SCREENSHOTS
I'm adding some screenshots to help you visualize the problem. To get those screenshots, I run the app on iPod Touch 5th generation with iOS 6. The behavior is different on iPhone 4 with iOS 7 (it behaves much better, but I still get the elements moving around some pixels).
Everytime I press the "Update" button, I remove the view which contains the UICollectionView from its superview (the entire screen) and add it again. I do not destroy this view, it is created only once. I thought that could be the origin of the problem (some autolayout calculation buffer holding values from previous layout), but destroying it didn't solve the problem (altough it did make the displacements less frequent and disturbing, but at the cost of performance).
This is the expected behavior. This is the view I get when the app open:
Misplaced views. This is the result of pressing the "Update" button for the first time:
Result after pressing the button a second time:
Result after pressing the button a third time:
If I keep pressing the button, I get layouts alternating between screenshots 3 and 4 (or at least they look pretty like the same).
I'M GIVING UP AUTOLAYOUT AND HERE IS WHY
Well, I'm really giving up using auto layout. I've spent almost a week learning to do a lot of thing with it (specially laying out and animating views). I thought it is a wonderful and powerful feature and I learned to love it. But then I needed to support iOS6 and iOS7.
I found it only works great on iOS8 (with any device, old or not). I don't know if I'm doing something really stupid, because I can't find any threads on the internet talking about three killing problems I've been facing.
I'll list them here just in case somebody come across this thread sometime in the future with the same problem or with a solution. They are listed ordered by the priority I gave to them to why I'm giving up autolayout.
1) Performance
Autolayout runs really slow on iOS6 and a little slow on iOS7 (compared to iOS8 - remember I'm developing with XCode 6.2 and iOS8.2 SDK). The same hardware with iOS8 runs the same code just fine.
To get to this conclusion, I ran my app in two iPod Touch 5, one with iOS6 and the other with iOS8. The difference in performance was pretty clear. Loading or dismissing a simple view (11 subviews) in iOS6 could take more than 5 seconds (on iOS 8, never took more than 1). On iPhone 4 with iOS7, the same code performed much better than in iOS6, but slower than in iOS8.
I'm sure it is an autolayout related problem because, using the same code, I disabled autolayout (and size classes) for some specific XIBs and they runned stupendously fast on iOS6, while the other views kept being slow (if you are going to try this, remember to delete the old app, clean the project and build it again, or it will still use autolayout).
2) Random crashes on specific devices with iOS6 or 7 when dismissing a view controller or removing a view from its superview
The problem is clearly stated here. It seems I'm bumping into the float error problem, because I can see some e-08 numbers on the crash log.
This is a serious problem for autolayout adoption. It's a random, unpredictable - but reproducible - crash. The same layout constraint can work in various devices, with different iOS versions. But it can also crash in some of them. Example: I had a view that worked fine on iPhone 4 (iOS7) and that crashed when dismissed on iPad Air (same iOS). The solution? Change the constraint's items relation from
x.width = y.widht*0.8 + 0
to
y.width = x.widht*1.25 + 0
which is equivalent matematically, but avoided the crash.
I searched a lot if anybody had a way to know when this crash could happen or how to tackle it down forever, so I could make my views without having to worry about testing them on every device, with every iOS version, to make sure it wouldn't crash. I couldn't find a away to fix it.
This crash doesn't seem to happen in iOS8.
PS: I tried removing the constraints from all my subviews before removing the view from superview, but then the crash occurred when removing one constraint. I couldn't find any good reason to why it was crashing when removed.
3) The problem I describe in the first part of this question
It's a third priority problem because I could solve this designing the cells without autolayout. This would be a minor problem if the rest of the app do not use cells, which is the case.
But it is still a problem I cannot understand nor solve with autolayout. When I remove autolayout, the cells are displayed just fine. And they do work fine on iOS8 and I double checked if I was using some specific iOS8 feature and I'm not.
BOTTOM LINE
I'm giving up autolayout while I have to support both iOS6 and 7 or until I can find a way to fix at least the first two problems I listed above.
I've tasted the power of Autolayout and I really like it, but I can't develop worrying about unpredictable crashes hidden on some mysterious dismiss in a specific hardware with a specific iOS version. Nor can I accept the poor performance of iOS6 (sometime soon we should drop support to iOS6, though, so this will be a lost problem).

iOS app layout in the simulator different than on the actual device

My app looks completely different on a real device compared to a simulator. I used storyboard and used "add missing constraints" on all objects to remove warnings. Could this have caused the problem?
The actual device has most image views collapsed in the upper left corner
The simulator (for all devices you can test with) shows all 4 images filling the screen
Thanks!
A likely cause would be Autolayout constraints that do not create the intended effect.
You may be seeing the expected behaviour in the simulator simply because it has old cached versions of the NIB files... sometimes will get device/simulator differences due to this. Alternatively, could be the app on the device that has the old version. A clean build may result in problem resolved or seeing the same problem in both places, either of which solves half the question.
Using the automatic "Add missing constraints" is almost certainly the immediate cause here, if the problem occurred at the same time you did that.
Presuming you have the project under source control, I'd recommend rolling back and adding missing constraints in a more planned way, as the automatic system isn't smart enough for every scenario it seems.

iOS XCode Storyboard controls moved and now look strange in simulator

I am following the course on iOS through iTunes university and working on the calculator project. I moved the controls on the storyboard to make room for another control at the top. Everything looks fine on the storyboard but when run in the simulator, controls are bunch up, on top of each other, and some are clearly off the top of the simulator screen. This leads to the following very related questions.
How does one move controls around on the storyboard? I went to the size inspector of each control (buttons in my case) and changed the 'Y' value (increased it by 10). I did this for each control. I didn't think about it as I was doing it because as I said, all looks fine on the storyboard. Is there a better way to move controls around? I could not figure out how to grab more than one control at a time and move them. Grabbing all and moving or all but one and moving would have been ideal.
I anticipate someone is going to say, "We need more info. " How do I show the storyboard? Is there a xml file somewhere? How is the storyboard saved? How should I show the results of the simulator?
In general, what the heck is going on? Why would things look so different in the simulator?
Is there a better forum/group to ask newbie questions about iOS programming?
My specs are these:
XCode 4.5.2
Ios simulator versions set to 6.0 and iPhone
Any other info needed? Thanks in advance,
Dave
Try setting your simulated device size to 'freeform' instead of 'inferred'. This screen is a bit smaller so the controls are no longer overlapping. The latest xcode sets it by default to ios6 (screen size of iPhone 5)
edit For a better insight in xcode IDE, please refer to the documentation provided by apple (includes screenshots for clarity)
https://developer.apple.com/library/ios/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/000-About_Xcode/about.html#//apple_ref/doc/uid/TP40010215

Resources