通过下面的方法可以解决,UIScrollView 下拉时可以将与顶部空白区域填充为与顶部颜色一致的颜色!
- (void)createTotalScrollView
{
if (!_totalScrollView)
{
_totalScrollView = [[TPKeyboardAvoidingScrollView alloc]initWithFrame:CGRectMake(0, 0, kDEVICEWIDTH, self.frame.size.height)];
_totalScrollView.bounces = YES;
_totalScrollView.scrollEnabled = YES;
_totalScrollView.backgroundColor = TFCOLOR_EFEFEF;
_totalScrollView.delegate = self;
// 蓝色背景
UIView* backgroundView = [[UIView alloc] init];
backgroundView.backgroundColor = loadColor(@"#0093FF");
backgroundView.frame = CGRectMake(0, -200, kDEVICEWIDTH, 200);
[_totalScrollView addSubview:backgroundView];
if (iPhone4)
{
_totalScrollView.contentSize = CGSizeMake(kDEVICEWIDTH, kDEVICEHEIGHT + 140);
}
else if (iPhone5)
{
_totalScrollView.contentSize = CGSizeMake(kDEVICEWIDTH, kDEVICEHEIGHT + 30);
}
else if (iPhone6 || iPhone6Plus)
{
_totalScrollView.contentSize = CGSizeMake(kDEVICEWIDTH, kDEVICEHEIGHT - 60);
}
else
{
_totalScrollView.contentSize = CGSizeMake(kDEVICEWIDTH, kDEVICEHEIGHT);
}
[self addSubview: _totalScrollView];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat insetTop = 0;
if (offsetY >= 200) {
insetTop= 200;
}else{
insetTop = 0;
}
//解决设置contentInset与下拉刷新冲突问题
if (scrollView.contentInset.top >= 0 && (scrollView.contentInset.top <= 200))
{
scrollView.contentInset = UIEdgeInsetsMake(insetTop, 0, 0, 0);
}
}