ios - 无法用代码获取到NSLayoutAttributeTrailing的值为什么?
天蓬老师
天蓬老师 2017-04-17 17:09:36
0
1
737

我在storyboard中使用了autolayout,因此不能通过更改frame的值来更改控件的位置,使用如下方法:

-(void)replaceView:(UIView *)view constrainWithConstant:(CGFloat)constant attribute:(NSLayoutAttribute)attribute{

for (NSLayoutConstraint *constraint in view.superview.constraints) {
    if (constraint.firstItem == view && constraint.firstAttribute == attribute) {
        constraint.constant = constant;
    }
}

}
可以获取到NSLayoutAttributeLeading以及NSLayoutAttributeTop的值,并在代码中更改。但是无法获取到NSLayoutAttributeTrailing的值,请问我该如何用代码获取到NSLayoutAttributeTrailing的值并加以更改呢?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
黄舟

If trailing is set up in the storyboard, you should be able to get it (notice that you only judged the firstAttribute, maybe it is a problem with the order of adding it during the connection? Check the second and try it), if it is not set, just add it, no need to replace

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template