ios 悬浮按钮随tableview滚动动画缩进效果

cellLinkage.gif

使用scorllview监听滚动方法和masonry约束更新即可完成
核心代码

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

{
    
        NSLog(@"滑动开始");
    [UIView animateWithDuration:0.5 animations:^{
        [self.suspenBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(-45);
        }];
        [self.suspenBtn.superview layoutIfNeeded];
    }];
}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

{
    
        NSLog(@"滑动松开自动滑动开始");
    
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{
    
        NSLog(@"滑动结束");
    //    [self.view setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.5 animations:^{
        [self.suspenBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(0);
        }];
        [self.suspenBtn.superview layoutIfNeeded];
    }];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if(!decelerate){
        DDLogVerbose(@"----tableview停止滚动!!!!");
        //         [self.view setNeedsUpdateConstraints];
        [UIView animateWithDuration:0.5 animations:^{
            [self.suspenBtn mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(0);
            }];
            [self.suspenBtn.superview layoutIfNeeded];
        }];
    }else {
        DDLogVerbose(@"----tableview正在滚动!!!!");
    }
}

你可能感兴趣的:(ios 悬浮按钮随tableview滚动动画缩进效果)