首页 > 解决方案 > 需要随着底部列表滚动移动顶部的红色选择器

问题描述

我需要将上面显示的红色选择器与底部的水平滚动视图一起移动。目前它是在滚动完成后发生的。

这是我正在使用的代码:

- (void)scrollViewDidEndDecelerating1:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.x == 0) {
        [UIView animateWithDuration:0.25 animations:^{
            self.selectMessageCatagoriesLabel.frame = CGRectMake(0, 41, [CommonUtils getFlexibleWidth:125], 3);
        } completion:^(BOOL finished) {
        }];
    }
    else if (scrollView.contentOffset.x == 375) {
        [UIView animateWithDuration:0.25 animations:^{
            self.selectMessageCatagoriesLabel.frame = CGRectMake([CommonUtils getFlexibleWidth:125], 41, [CommonUtils getFlexibleWidth:125], 3);
        } completion:^(BOOL finished) {
        }];
    }
    else{
        [UIView animateWithDuration:0.25 animations:^{
            self.selectMessageCatagoriesLabel.frame = CGRectMake([CommonUtils getFlexibleWidth:250], 41, [CommonUtils getFlexibleWidth:125], 3);
        } completion:^(BOOL finished) {
        }];
    }
}

请检查屏幕截图以供参考

在此处输入图像描述

标签: iosobjective-ccocoa-touchuiscrollviewuiscrollviewdelegate

解决方案


您可以使用scrollViewDidScroll方法 from UIScrollViewDelegate,因此您可以在此方法中移动您的代码。您不需要在此方法中使用动画,因为它调用非常频繁。


推荐阅读