实现 UIScrollView 滚动条一直显示
实现原理正如网上各种所云,就不赘述了,但是好多人都只能实现到第二步(我开始也是,所以也给自己记录),也就是只有手动滑动过之后滚动条才会一直显示,而不是从一开始就一直显示,所以为了实现这一功能,请尽量按照步骤来,直接上代码。
一共有四步哦~
1、先来个分类(具体出处不记得了,还是感谢前辈)
@interface UIImageView (FJScrollView)
@end
#define noDisableVerticalScrollTag 836913
#define noDisableHorizontalScrollTag 836914
@implementation UIImageView (FJScrollView)
- (void)setAlpha:(CGFloat)alpha
{
if(self.superview.tag == noDisableVerticalScrollTag) {
if(alpha ==0&&self.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin) {
if(self.frame.size.width <10&&self.frame.size.height >self.frame.size.width) {
UIScrollView *sc = (UIScrollView*)self.superview;
if(sc.frame.size.height < sc.contentSize.height) {
return;
}
}
}
}
if(self.superview.tag == noDisableHorizontalScrollTag) {
if(alpha ==0&&self.autoresizingMask == UIViewAutoresizingFlexibleTopMargin) {
if(self.frame.size.height <10&&self.frame.size.height
UIScrollView *sc = (UIScrollView*)self.superview;
if(sc.frame.size.width < sc.contentSize.width) {
return;
}
}
}
}
[supersetAlpha:alpha];
}
@end
2、给UIscrollView或者其子类绑定对应的tag值
self.collectionView.tag = 836914;
3、处理数据之后
[self.collectionView reloadData];
[self.collectionView flashScrollIndicators];
__weak __typeof(&*self)weakSelf = self;
if (self.collectionView.contentOffset.x<=1) {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.collectionView setContentOffset:CGPointMake(1, 0) animated:NO];
});
}
4、喜欢~关注。如有问题请大神指出,望不吝赐教。