You are better of keeping a variable around e.g. var isBackgroundColorRed: Bool = true
And another for scroll y position when you set the background color to blue. e.g.
var blueBackgroundColorYOffset: CGFloat?
When you set the background color to blue, set the y offset, to the contentView.origin.y.
Then in the delegate for the tableview (which subclasses UIScrollView)
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if !isBackgroundColorRed {
// apply some color blending between blue and red based on
// the amount of movement on y axis, until you reach the limit
// its also important to take the absolute value of the blueBackgroundColorYOffset
// and the offset here in scrollViewDidScroll to cover up or down movements
// say 1 cell's height, then set your isBackgroundColorRed to true
}
}
Try adding this to your project and update yur bridging header.
UIColor-CrossFade
This technique will give you a nice UX rather than a sudden background change.