只要实现如下方法就可以实现你要的效果 非常简单 也是最low的一种方法
CGFloat alpha;
CGFloat startContentOffsetX;
CGFloat willEndContentOffsetX;
CGFloat endContentOffsetX;
1. 在你拖动的时候创建view 并设置它的颜色
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ //拖动前的起始坐标
startContentOffsetX = scrollView.contentOffset.x;
_ssssseeeeview = [[UIView alloc] initWithFrame:CGRectMake(startContentOffsetX, 0, 414, 736)];
_ssssseeeeview.backgroundColor = [UIColor grayColor];
_ssssseeeeview.alpha = 0;
[_scrollView addSubview:_ssssseeeeview];
}
2. 在你滑动scrollview的时候让它透明度变化
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
pageControl.currentPage = _scrollView.contentOffset.x/self.view.frame.size.width;
CGFloat size = _scrollView.contentOffset.x;
if ( startContentOffsetX== 0) {
alpha = size/self.view.frame.size.width;
}
else if (size<= startContentOffsetX && size>=0 && startContentOffsetX<=self.view.frame.size.width )
{
alpha = 1-size/self.view.frame.size.width;
}
else if ( size>startContentOffsetX && size<=(startContentOffsetX+self.view.frame.size.width))
{
alpha = (size-startContentOffsetX)/self.view.frame.size.width;
}
else if ( size<=startContentOffsetX && size>= self.view.frame.size.width)
{
alpha = (startContentOffsetX-size)/self.view.frame.size.width;
}
if (size != startContentOffsetX) {
_ssssseeeeview.alpha = alpha;
}
}
3. 在你滑动将要停止的手删除你所创建的view
#pragma mark - 将要停止前的坐标
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
willEndContentOffsetX = scrollView.contentOffset.x;
[_ssssseeeeview removeFromSuperview];
if (_view != nil) {
[self buttonClick:(UIButton *)[self.view viewWithTag:1002]];
[_selecotView removeFromSuperview];
[_view removeFromSuperview];
}
}
#pragma mark - 减速停止(必须得有快速拖动的动作,scrollView滚动完毕(速度减为0)并且手已经松开的时候调用)
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
endContentOffsetX = scrollView.contentOffset.x;
}