I want to believe this is a simulator bug, but, can somebody please explain what is going on?
Im running a simple View on my storyboard: (as you can see, the view with green background is my superview). The thing is when I run my app on a simulator (sometimes, not always) my superview doesn't get scaled and I get a black screen!! My view has checked true the Use Autolayout field, cause some things inside need to have constraints.
I can't give constraints to my view because, it's the superview
And yes, I have debugged with the UI and this is the thing, my superview is not resizing.
Okay I solved, for sure is a bug of Xcode. For me was very strange, so, I decided to delete my View Controller and add all my elements again.
Related
I have a strange bug where bottom button hides below the screen. The strange thing is that it is actually tappable and in View Hierarchy it displays as it should be. How could this be? How to debug this problem? Frame and constraints are expected and ok.
Sorry I cannot make a simple example to reproduce because I do not know where the problem lies.
XCode 11, iOS 13
I just had a similar experience. Searching around, I found that my view did not have a Safe Area defined (Use Safe Area Layout Guides was not checked in File Inspector). This was an old XIB from prior to Safe Area guides.
After changing this and then adjusting my AutoLayout constraints to reference this rather than the View, things started aligning properly and the View Hierarchy and Simulator matched.
Not sure if this is an absolute answer to your situation, but it solved mine which seems similar.
I'm trying to place a tableView in a viewController, but im not able to constraint properly the tableView, i'm doing the usual things, i'm sticking the leading, trailing and bottom constraints to superview, and some space to the top superview. But as shown in the preview, table view does not look to be constrained, the effect that it brings for me is that when i put elements into content view, they extend along the right side i can not see them for small devices. Does anyone know what could be happening?
Thanks in advance!
StoryBoard Tree
After spending long time checking what happened i figured out that there is a Xcode fail on it, i run it in simulators and real devices and it works perfect, the bad thing is that everything i inserted into that view does not look as it should in the preview, but again, in simulator everything works fine. So, preview is not always as trusty as i expected and now i know it
I'm trying to use view controller that I decided to use auto layout for. Before I used auto layout, the view showed normally like how I intended it to during runtime. But I decided to switch to auto layout (because after all, bigger iPhones are coming), and even after setting it up, getting no issues at all, and seeing that the app scaled well to the iPhone size in IB; I still have a blank screen. To prove it, here are pictures:
So why is this happening? I added the constraints in the square view, and it gracefully scaled to the iPhone view in Interface Builder. If you also look at the sidebar, the alerts for auto layout errors are not present. And IB is rendering everything. But why is the simulator blank?
And yes, I connected all the elements to be code correctly. I verified. And yes, I have code that puts text in a label. Here it is, in the 'viewDidLoad()' method:
override func viewDidLoad() {
super.viewDidLoad()
self.titleLabel.text = "Hello, World!"
}
And I will reemphasise: the app worked before I did auto layout. For this build, I deleted all the elements, relocated them, reconnected them, and added tweaked the view with auto layout unit IB rendered it correctly. But I'm getting different results here.
Please help me. Oh, and sorry for the massive images, I can't figure out how to shrink them.
EDIT: I've gone through and used the view debugger, and tried to capture the view hierarchy to look for clipping or occlusion. Funny enough, the view debugger shows the content properly, and there wasn't any clipping or occlusion that I saw. When I tried to show frames in the simulator though, it didn't show anything. I'm starting to think that this is a simulator bug. Currently, I'm using Xcode 6 beta 6.
I recreated the issue by adding a collection view to a standard view controller and this seems to be the problem:
Having Xcode add suggested constraints gives you this, which causes the view to not show up.
It is aligning the view's left and right to the layout guides (which doesn't seem to be right)
You will have to manually add spacing constraints to your view.
This is what you want:
Try turning on the assistant editor and use Preview while tweaking your constraints.
(source: mattknott.com)
Do your Editing in "wAny hAny For All Layouts Base values" mode. then you will not see blank screen while testing on different devices.
Mode selection can be one from bottom bar.
Good Luck
I have a UILabel that i placed in the top left corner of the screen in the Storyboards. I disabled "Autolayout" and it works perfectly fine on the iPhone 5 screen. The problem comes when i try them on any of the smaller screens like the iPhone 4. The label is then placed on the bottom right corner. After this issue, i tried to programmatically 'fix' the position in the "viewDidLoad" method of the view controller, but it stills moves position and the problem continues.
Ive been scratching my head about this for a while!
Any help would be appreciated.
I would suggest that you turn autolayout back on. If you get the constraints right, this situation (two different screen sizes) is exactly the sort of thing autolayout is really good for. There's a very good reason why Apple migrated autolayout from OS X to iOS at exactly the moment the iPhone 5 screen appeared on the scene!
try to fix it at viewWillAppear
Go to the utilities panel, click the tab "Show size inspector", and change the autosizing. Then drag your component in your storyboard's view so that it stays in one of the "borders". If you do not need to support older iOS versions, I'd recommend you to figure the proper way with auto-layout though.
I moved all my UIButtons to fit on a particular UIImageView and for some reason they're not matching up the to correct location as the storyboard when run on the simulator nor the iPad itself. It's weird and I'm confused.
This is a screenshot of it in the storyboard.
This is a screenshot of it on the simulator.
Notice how some of circles(buttons) the titles are shown. Why is this happening and how can I get them into the position they are in the storyboard? Thanks for the help :)
Okay, for some reason i disabled the auto layout thing on the storyboard. But, when i reenabled it it seemed to work. Strange bug, but the problem is fixed now. Thanks larme, for making me aware of the auto layout thing.