당신은 오프셋 비율에 따라 색상을 만들어야합니다.
이와 같이 색상 사이에 쉬프트를 만드는 가장 쉬운 방법은 HSB 색상 공간을 사용하는 것입니다.
또한 애니메이션이 아닙니다. "애니메이션"효과는 스크롤 뷰에서 사용자에게 제공됩니다. 스크롤보기가 변경 될 때마다 색상을 설정하면됩니다.
위임 메서드에서 이와 비슷한 작업을 수행 할 수 있습니다.
편집 내가 RGB 방식이 중간 값에 수행 방법을 모르는
// this just calculates the percentages now and passes it off to another method.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// vertical
CGFloat maximumVerticalOffset = scrollView.contentSize.height - CGRectGetHeight(scrollView.frame);
CGFloat currentVerticalOffset = scrollView.contentOffset.y;
// horizontal
CGFloat maximumHorizontalOffset = scrollView.contentSize.width - CGRectGetWidth(scrollView.frame);
CGFloat currentHorizontalOffset = scrollView.contentOffset.x;
// percentages
CGFloat percentageHorizontalOffset = currentHorizontalOffset/maximumHorizontalOffset;
CGFloat percentageVerticalOffset = currentVerticalOffset/maximumVerticalOffset;
[self scrollView:scrollView didScrollToPercentageOffset:CGPointMake(percentageHorizontalOffset, percentageVerticalOffset)];
}
// this just gets the percentage offset.
// 0,0 = no scroll
// 1,1 = maximum scroll
- (void)scrollView:(UIScrollView *)scrollView didScrollToPercentageOffset:(CGPoint)percentageOffset
{
UIColor *HSBColor = [self HSBColorForOffsetPercentage:percentageOffset.x];
UIColor *RGBColor = [self RGBColorForOffsetPercentage:percentageOffset.x];
}
// HSB color just using Hue
- (UIColor *)HSBColorForOffsetPercentage:(CGFloat)percentage
{
CGFloat minColorHue = 0.0;
CGFloat maxColorHue = 0.2; // this is a guess for the yellow hue.
CGFloat actualHue = (maxColorHue - minColorHue) * percentage + minColorHue;
// change these values to get the colours you want.
// I find reducing the saturation to 0.8 ish gives nicer colours.
return [UIColor colorWithHue:actualHue saturation:1.0 brightness:1.0 alpha:1.0];
}
// RGB color using all R, G, B values
- (UIColor *)RGBColorForOffsetPercentage:(CGFloat)percentage
{
// RGB 1, 0, 0 = red
CGFloat minColorRed = 1.0;
CGFloat minColorGreen = 0.0;
CGFloat minColorBlue = 0.0;
// RGB 1, 1, 0 = yellow
CGFloat maxColorRed = 1.0;
CGFloat maxColorGreen = 1.0;
CGFloat maxColorBlue = 0.0;
// if you have specific beginning and end RGB values then set these to min and max respectively.
// it should even work if the min value is greater than the max value.
CGFloat actualRed = (maxColorRed - minColorRed) * percentage + minColorRed;
CGFloat actualGreen = (maxColorGreen - minColorGreen) * percentage + minColorGreen;
CGFloat actualBlue = (maxColorBlue - minColorBlue) * percentage + minColorBlue;
return [UIColor colorWithRed:actualRed green:actualGreen blue:actualBlue alpha:1.0];
}
더 유연하게합니다. 중간에 갈색이 생길 수도 있지만 ... 놀 수 있습니다.
ANYTHING을 제어하는 방법으로 스크롤보기를 사용하는 방법에 대한 아이디어를 얻을 수 있습니다.
불투명도, 크기, 회전, 글꼴 크기 등을 제어 할 수있는이 방법을 사용하면 여러 가지를 결합 할 수도 있습니다 (예 : RGB와 동일).
감사합니다. 완벽하게 작동합니다! – Berendschot
이것이 RGB 색상에서 작동 할 가능성은? – Berendschot
@ Maarten1909 그래,하지만 RGB로 변하는 색상을 만드는 것이 훨씬 어렵다. 내가 그것을 초로 바꿔 줄게. – Fogmeister