Bug 57007 - Cannot constrain UIView to Leading or Trailing of an UIViewController
Summary: Cannot constrain UIView to Leading or Trailing of an UIViewController
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS Designer ()
Version: 4.5.0 (15.2)
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-05-31 14:19 UTC by Rodrigo Lira
Modified: 2017-07-11 17:44 UTC (History)
9 users (show)

Is this bug a regression?: ---
Last known good build:

UIViewController layout guides displayed within the Controller itself. (7.86 KB, image/png)
2017-05-31 14:19 UTC, Rodrigo Lira

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Rodrigo Lira 2017-05-31 14:19:05 UTC
Created attachment 22589 [details]
UIViewController layout guides displayed within the Controller itself.

After placing a new UIViewController on a Storyboard, I add an UIView and then I try to create a constraint to the Leading or Trailing anchor of that controller. As the attachment shows, the layout guide is displayed inside the controller. I thought that was a visual bug but when I ran on simulator the view is not touching the leading/trailing anchor (even with the constant set to 0).

I get this error on the Mac and on Windows. Both are updated to the latest stable version (10.10, May 24, 2017).

As a workaround, following a topic on Xamarin Forums, I've overwritten Xamarin.iOS on the Mac back to 10.8 (Apr 6, 2017). I had to edit the version inside the storyboard file in order to edit it with the downgraded version.

Link to forums discussion:

Comment 1 Rodrigo Lira 2017-06-01 14:29:28 UTC
After trying out uninstall / install everything again, I can see that the bug does not happen on Xamarin Studio for Mac.

It happens on Visual Studio for Mac and also on the Visual Studio extension for Windows.

To someone who can, please help me classify
Comment 2 Alan McGovern 2017-06-01 14:58:32 UTC
By default the constraints are relative to the margin of the top level view in a viewcontroller. Once you create the margin based constraints, just select them and use the property panel to uncheck the 'relative to margin' setting. This will give you the edge constraint you are looking for.

We are actively working on alternative ways to create edge versus margin constraints. Most of that work is complete but it is not ready to ship as of yet.
Comment 3 Rodrigo Lira 2017-06-01 15:39:04 UTC
A few comments on that:

So, if I'm understanding correctly, when I add a new UIViewController, it's top leve UIView now has default margins, is that right? It didn't use to have but it does now (I'm assuming that since I could constrain a Label to the edge without any additional settings).

If that is true, how come it doesn't happen on Xamarin Studio on the Mac? It currently presents the "old" behavior. ie, let's me constrain to the edge.

I tried following your suggestion. Started a new Single Page iOS App on Visual Studio on Windows. Dropped an UIViewController. Dropped a UILabel. I drag the UILabel's leading anchor to the UIViewController's View margin (as shown in the attachment). Then, I select the constraint and there's no property "relative to margin".

Sorry if I misunderstood your comment.

Ps.: I'm setting it back to reopened just because I assume that is the flow. I'm sorry if it's not. First time here. I couldn't find the specific workflow diagram for Xamarin (only one available is the one at bugzilla's general docs).
Comment 4 Marco Burato 2017-06-12 15:15:09 UTC
Came here because I've just hit the same issue.

Rodrigo, the option "Relative to margin" is in the menu that appears when you click the "First Item" or "Second Item" fields.
Then, you also need to change the Constant to 0.
And if you use the document outline to quickly select the other constraint you can't type the "0" in the Constant field. This has been broken since... forever.

This workaround works but it's a pain. IMHO this is a bug and should be fixed ASAP. Working with constraints is already difficult enough.
Comment 5 Pierce Boggan [MSFT] 2017-07-11 17:44:15 UTC
Thanks so much for taking the time to submit this report! As @Alan stated in Comment #2, this is the intended behavior and is actually the same way this works in Xcode after Xcode 8. The iOS Designer is merely mirroring that existing behavior.