【问题标题】:NSLayoutConstraint not updating after modifying in scrollViewDidScroll method in iOS7在 iOS7 的 scrollViewDidScroll 方法中修改后 NSLayoutConstraint 不更新
【发布时间】:2016-09-15 09:22:02
【问题描述】:

我有一个连接到情节提要的 IBOutlet NSLayoutConstraint 属性:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleViewTopConstraint;

当滚动视图滚动时,我在 scrollViewDidScroll 方法中修改了这个约束:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGFloat yOffset  = scrollView.contentOffset.y;

        if (yOffset <= -20) {
            [self.logoView mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(@(yOffset));
                    make.height.equalTo(@(fabs(yOffset) + self.ImageHeight + STATUSBAR_HEIGHT))}];

         }

        CGFloat top = self.ImageHeight - self.titleView.height - yOffset - 20;
        self.titleViewTopConstraint.constant = top;
        if (self.titleViewTopConstraint.constant < 25) {
            self.titleViewTopConstraint.constant = 25;
        }
}

我正在尝试在滚动视图滚动时更新常量,它在 iOS8 中运行良好。但是在 iOS7 中设置后,该常量似乎没有更新。

知道什么会导致这个问题,我该如何解决?谢谢。

【问题讨论】:

    标签: ios ios7 autolayout nslayoutconstraint


    【解决方案1】:

    您需要调用layoutIfNeeded 来更新视图约束。因此,一旦您更改了约束值,请在下方拍摄。

    [self.view layoutIfNeeded];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 2015-06-11
      相关资源
      最近更新 更多