需要移动顶部红色选择器以及底部列表滚动

问题描述 投票:0回答:1

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

这是我正在使用的代码:

- (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) {
        }];
    }
}

请检查屏幕截图以供参考

enter image description here

ios objective-c cocoa-touch uiscrollview uiscrollviewdelegate
1个回答
0
投票

您可以使用scrollViewDidScroll中的UIScrollViewDelegate方法,因此可以在此方法中移动代码。您无需在此方法中使用动画,因为它经常调用。

© www.soinside.com 2019 - 2024. All rights reserved.