Re: Autolayout fixed size centering in VFL
Re: Autolayout fixed size centering in VFL
- Subject: Re: Autolayout fixed size centering in VFL
- From: Luther Baker <email@hidden>
- Date: Fri, 04 Oct 2013 23:29:02 -0500
> Also, I suspect the reason you're specifying center-X alignment when
creating the vertical constraints is because NSLayoutConstraint threw an
exception when you tried to use the center-Y alignment option. That
should be warning enough. ;-)
This is true - as I typed this block into my own project I naturally lined
up the "V:" vfl string with the Y constant and the "H:" vfl string with the
X constant ... and it complained. I then noticed that
evgenyneu<https://github.com/evgenyneu/center-vfl> had
flipped them.
Thanks - it now feels like this is an anomaly at best.
-Luther
On Fri, Oct 4, 2013 at 11:03 PM, Kyle Sluder <email@hidden> wrote:
> On Fri, Oct 4, 2013, at 08:22 PM, Luther Baker wrote:
> > First of all ... very much appreciate you both so often! Thanks for
> > commenting as much as you do.
> >
> > I too faced this issue and, like Kyle, read enough to assume it was
> > generally not possible with VFL. But this afternoon, I came across this:
> > https://github.com/evgenyneu/center-vfl and for my specific case, it
> > works
> > perfectly. Let me know what you think ... and if you see caveats. I'm
> > successfully using this technique to center an ImageView populated with
> > an
> > image much larger than the iPhone's screen on a simple, standard plain
> > old
> > ViewController's view.
>
> This doesn't work on OS X, and I'm surprised it works on iOS.
>
> > UIView *superview = self.view;
> > NSDictionary *variables =
> > NSDictionaryOfVariableBindings(label, superview);
> > NSArray *constraints = [NSLayoutConstraint
> > constraintsWithVisualFormat:@"V:[superview]-(<=1)-[label]"
> > options:
> > NSLayoutFormatAlignAllCenterX
> > metrics:nil
> > views:variables];
> > [self.view
> > addConstraints:constraints];
>
> This specifies a relationship between the superview's bottom edge and
> the label's top edge, yet the label is a subview of the superview. When
> running on the Mac, I would expect NSLayoutConstraint to complain here ,
> but I can see why it might not if the "|-" syntax is treated as a simple
> shortcut for whatever the superview happens to be.
>
> Indeed, if you try the equivalent on the Mac, you can see that this code
> throws an exception because it tries to install a constraint relating a
> view to another view upon that view itself:
>
> """
> Unable to install constraint on view. Does the constraint reference
> something from outside the subtree of the view? That's illegal.
> constraint:<NSLayoutConstraint:0x104406a00
> V:[NSView:0x10060da80]-(<=1)-[NSTextField:0x10012ac00]> view:<NSView:
> 0x10060da80>
> """
>
> I've forked the project you linked to and uploaded my demo:
> <https://github.com/kylesluder/center-vfl/>
>
> Also, I suspect the reason you're specifying center-X alignment when
> creating the vertical constraints is because NSLayoutConstraint threw an
> exception when you tried to use the center-Y alignment option. That
> should be warning enough. ;-)
>
> --Kyle Sluder
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden