如何使用NSLayoutAnchor设定乘数值?
例如,,我们可以使用NSLayoutConstraint来完成乘数值为1.5的操作:
UIView *view1 = [[UIView alloc] init];
view1.translatesAutoresizingMaskIntoConstraints = false;
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];
NSLayoutConstraint *hConstraint = [NSLayoutConstraint constraintWithItem:view1
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1.5 constant:0.0f];使用NSLayoutXAxisAnchor时没有可用的乘法器参数。
hConstraint = [view1.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor constant:0.0f];只能指定常量值。
发布于 2017-01-17 10:20:13
该NSLayoutAnchor方法有两个变体,它们接受乘数,但它们只能在NSLayoutDimension锚点(宽度和高度)上使用:
func constraint(equalTo anchor: NSLayoutDimension, multiplier m: CGFloat) -> NSLayoutConstraint
func constraint(equalTo anchor: NSLayoutDimension, multiplier m: CGFloat, constant c: CGFloat) -> NSLayoutConstraint有关更多信息,请参阅这份文件。
发布于 2019-04-05 06:13:55
如果我们只计算equalTo方法
这两种方法都是由NSLayoutAnchor的子类自动生成的。
2.nslayout维度有三个methods.This类是NSLayoutAnchor的子类。
3.NSLayoutXAxisAnchor只有一个相同的方法,这类是NSLayoutAnchor的子类
4.因此,NSLayoutYAxisAnchor只有一个相同的方法,这个类是NSLayoutAnchor的子类。
https://stackoverflow.com/questions/41691833
复制相似问题