I built a custom view controller. It has 1 tableview, 2 views and 1 map. When I set the constraints for this layout it works fine. I close project and reopen the map view out of the view controller. The width and height are 1000 points. If I set the map on top of this stack, there is no problem. But when I set map in the middle of the other views, a problem happens. I must put this mapview inside another view or it affects the others, but the problem is still there.
I use Xcode 8 beta 5, and constraint is 0 0 0 0
I have the same issue in the latest beta. I believe the problem is in the wrong default size, that is always set to 1000x1000 by Xcode for MKMapView.
I would wait for the fix in the next Xcode version.
If you, by some reason, really need it fixed now, you can setup a UIView with constraints as required, then put MKMapView inside the UIView and use Autoresizing to scale it.
Related
I have an issue that makes no sense to me. I have the following setup:
| UITableView |
|| UITableView header ||
||| UIView |||
So inside my UITableView header I have a container view that has leading, trailing and top constraints to its superview. Everything is set up correctly for my test device size (which is iPhone 8). If I change the test device to iPhone 8 Plus I get a strange offset for my trailing constraint - 39pt to the right edge, which is exactly the difference between iPhone 8 plus width in points and iPhone 8.
When I switch between devices in Xcode and see that the trailing constraint is not correct I just make an adjustment myself (change trailing to 1 and then back to 0) and the problem goes away for the particular device.
Initially I thought it is bug in Xcode but when I tested on a device the problem is still there.
I tried setting up a new view controller and adding the same elements but with no effect.
I am attaching screenshots to make my issue clearer.
Before: Adjusting the desired constraints
After: Switching to a device with different size
Adding this as an answer because it's too much for a comment - even though it's really just a confirmation, not a solution.
OK - looked at your project.
I'd say it's an IB / Storyboard bug, which I've seen in other circumstances. If you change the View As... device, the frame does not update immediately.
However, if you change anything that would cause a layout update - such as temporarily changing the background color of a view or font size of a label - everything should snap into place.
You'll also notice that if you select an element and move it slightly, the Update Frames button / menu item becomes enabled... and that will also correctly update the frames.
Note: When I ran the app, regardless of how the layout looked in Storyboard, the constraints correctly sized the views at run-time.
At first I accepted DonMag's answer (thanks for your time) as this really seemed to be an Xcode Interface Builder bug. As I investigated further when having the scenario I mentioned auto layout constraints are not updating the layout when I need it hence not giving me the right view.bounds.
I tried getting it in viewDidLayoutSubviews() without success as well - it was still giving me a size that suits another device.
What did the trick was calling view.layoutIfNeeded() before working with view's bounds. What it does is to update the view's layout immediately. As a result you can access the desired view's bounds.
I have quite a lot of views that are created with storyboards. Everything except 2 items in the views are not working correctly and it has to do with the constraints. It is almost like the constraints simply are not working or something.
When I am in the storyboard mode and change the constant value on the constraints, then 'update frames' nothing happens. It doesn't shift around like it typically does when constraints change.
This is inside a table cell. I have a view that is .5 thick that I want to stick to the bottom, and then I want it to extend to the trailing edge and to the leading. When I set any of these constraints then press 'update frames', nothing happens.
The other control I'm having an issue with is a TextView. It seems to have no height when in the application so again, something is going on with the constraints. This looks to be the same thing happening in this case too.
I have tried recreating the view in Xcode 8 (just this one view that I'm having issues with inside my storyboard) and I get the same weird behavior. I also tried saving it as Xcode 7.x mode as suggested in another thread, and I've also tried setting viewNeedsLayout in the code. Neither of those are working.
Any suggestions?
I see this issue here too. As a workaround:
Drag the affected view to a slightly other position (in Storyboard).
Now the (->) shows up to signal the current position does not match the constraints:
Click the (->)and choose "fix misplacements":
So I've now figured out issues for both of my issues.
It was a view that was 0.5 height but it did not have a constraint to be at that height. I added a constraint, updated frames, and it updated to be correct as I would expect.
No clue how something like this could be fine in Xcode 7 then in Xcode 8 it works. Apple really doesn't make developing easy huh.
2.
The textview I was using had a height constraint set to <= 107. Well I changed it to = 107 and now it works fine. = actually works for me too since I'm changing the constant dynamically in the code anyways. However, again, I still have no clue why this would work fine in Xcode 7 and not Xcode 8.
I'm working on my first swift app and I found out quickly that I need to use constraints to properly layout my page. So far I'm running into two issue.
The first one is that after adding some constraints, my view is pushed off the screen on the storyboard, but it looks fine(outside of my second issue) in the Assistant editor.
My second issue is that on some phone sizes the constraints are causing the text fields to expand when viewed in the Assistant editor and on an iPhone 6s test device.
I've added some screen shots below. Any help with this issue would be really appreciated.
Each time you add a constraint in storyboard, it is not automatically applied to your working view. You may think it should be applied immediately, but try to think think like this. If you have a view, and you apply height constraint (for example) and if Xcode applied it automatically you would get a view of width 0, since you haven't applied width constraint. That's why you need to tell Xcode to update constraints explicitly.
So when you want to update constraints, select view you want to update and go to Resolve Auto Layout issues, and click on Update Frames. This is located in the bottom right corner of your storyboard. It looks like a small triangle between two lines. Here you can update all views or just selected views.
For the second issue, you need to apply fixed width constraint to your stack view, instead of adding leading and trailing constraints. By doing that stack view will have the same width on each device.
(iOS 8, Xcode 6.1, Objective-C, iPhone/iPad)
I'm experiencing some weird behavior Xcode. Anyone else see this?
Steps to reproduce:
1. Drag two webviews into the same view
2. Resize one of the view by grabbing one of the little handles on the corners.
3. Other webview's width and height, and X and Y coords are set to 0 for the other webview?!
In Figure 1 below, I have two webviews. I have selected one, grabbed it by a handle to resize.
After releasing the mouse button, the second webview's coordinates and dimensions have all been set to 0.
i'm hoping that you are using AutoLayout in your xib or storyboard. You can fix this by disabling AutoLayout in your xib/storyboard. BUT if you want to use Autolayout in your views then you should set constraints in your UI elements.
In your case you should set constraints in Webview on the right side then drag and drop or resize the web view on the left side.
I'm guessing that Xcode is getting confused and setting them to (0,0,0,0) by checking their constraints.
This is also mentioned here
I'm fairly new to Interface Builder and I'm trying to practice it with a very simple view. Basically, I have 3 UIViews on my view controller. The problem I am having is that whenever I adjust the frame of 1 of the UIViews, the other 2 will disappear.
Here is a short 7 second video of the problem: https://vine.co/v/OMlbMIdWMe5
If I run the app on my device, I only see 1 of the views (the 1 I was adjusting) - the other 2 remain hidden.
I am using Xcode 6.1 . What could be causing this?
***EDIT: If I add 1 constraint to a view, it won't disappear when I readjust the frame of the other view. That is:
Add a constraint to ViewOne then readjusting size of ViewTwo will only cause ViewThree (without any constraints) to disappear.
So the solution is to add constraints to all 3 views before readjusting the frame of any of them. But still, what could be causing this issue?
This is an issue with Xcode 6.1, and has been reported to apple. A similar post can be found here.
WORKAROUND: I have found that you can edit the constraints in the right hand pane of the storyboard editor, in the size inspector. It actually does not prove that tedious.
You can disable autolayout if you don't need it, that helps.
Otherwise, wait for next patch~