UIScrollview animation depending on content offset

后端 未结 3 841
渐次进展
渐次进展 2020-12-30 15:53

I\'m using a horizontal UIScrollView, and I want a background color transition depending on the x value of the content offset.

Example: The width o

3条回答
  •  [愿得一人]
    2020-12-30 16:22

    In your scrollView delegate try something like this:

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
        CGPoint a = self.mainScrollView.contentOffset;
        if(a.x >= 320){
            [UIView animateWithDuration:0.5 animations:^{
                [self.view setBackgroundColor:[UIColor redColor]];
            }];
        }
        else{
            [UIView animateWithDuration:0.5 animations:^{
                [self.view setBackgroundColor:[UIColor yellowColor]];
            }];
        }
    }
    

提交回复
热议问题