调用layoutIfNeeded时的无限循环

时间:2017-09-20 15:14:15

标签: ios objective-c xcode

我有一个方法,通过一些委托,管理我的应用程序基础动画(UIAnimateWithDuration)。 这个方法在我的应用程序中无处不在。更新到Xcode 9后,该方法仍然有效,但在一个控制器中它不会。 它似乎通过以下消息生成无限循环:

  

警告:无法执行支持代码来读取进程中的Objective-C类数据。这可能会降低可用类型信息的质量。

[self.view layoutIfNeeded]被调用时。

这里是片段:

//MyTableViewDelegate.m
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.y <= 0.) {
        [self.presenter gestureAnimationWithConstant:scrollView.contentOffset.y alpha:__alphaMaxContainer];
        return;
    }
}

//MyPresenter.m
-(void)gestureAnimationWithConstant:(float)y alpha:(double)alpha{
    [self.view animationOnScrollingWith:y];
}

//MyViewController.m
-(void)animationOnScrollingWith:(float)constant{
    self.constraint.constant += 1;
    [self.view layoutIfNeeded]; //here it fires infinite loop

    if (self.constraint.constant > - (self.containerView.frame.size.height-10)){
        [self constraintAnimationWithAlpha:constant alpha:__maxAlphaContainer enableGesture:NO];
    }
}

-(void)constraintAnimationWithAlpha:(float)constant alpha:(double)alpha enableGesture:(BOOL)enableGesture{
    [UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:1.0 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.constraint.constant = constant;
        [self.view layoutIfNeeded];
        [self changeTopSectionAlphaValue:alpha];
    } completion:^(BOOL finished) {
        if (enableGesture)
            self->__gesture.enabled = YES;
        [UIView animateWithDuration:0.3 animations:^{
            [self.view layoutIfNeeded];
        }];
    }];
}

有什么想法吗?我疯了!

0 个答案:

没有答案