背景:为了让用户知道给页面可以滑动,一直显示滚动条来提醒用户。
先上代码:
#define noDisableVerticalScrollTag 836913
#define noDisableHorizontalScrollTag 836914
@implementation UIImageView (ForScrollView)
- (void) setAlpha:(float)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 < self.frame.size.width) {
UIScrollView *sc = (UIScrollView*)self.superview;
if (sc.frame.size.width < sc.contentSize.width) {
return;
}
}
}
}
[super setAlpha:alpha];
}
@end
代码来自: http://www.developers-life.com/scrollview-with-scrolls-indicators-which-are-shown-all-the-time.html
代码的用法是Category
原理是:因为scrollView的Indicators是一个imageView,通过alpha来显示和隐藏。然后通过设置ScrollView的tag确定是哪个imageView
调用方式:
在viewDidAppear内
self.textView.tag = 836913;
[self.textView flashScrollIndicators];
一般如上代码就行了,如果不行,请尝试如下代码
同样在viewDidAppear内
self.textView.tag = 836913;
[self.textView performSelector:@selector(flashTableScrollIndicators) withObject:nil afterDelay:0];