希望帮助后来开发者节省时间更多投入到其他逻辑上
UITextView继承自 UIScrollView,所以通过定时器调用 flashScrollIndicators 方法 即可一直显示滚动条。
@interface GYTextView : UITextView
@property(nonatomic) CGFloat verticalScrollBarH;
@property(nonatomic,strong)NSTimer *timer;
@end
import "GYTextView.h"
@implementation GYTextView
-(instancetype)initWithFrame:(CGRect)frame{
if (self=[super initWithFrame:frame]) {
self.tag = 836913;
if (@available(iOS 10.0, *)) {
self.timer=[NSTimer scheduledTimerWithTimeInterval:0.4 repeats:YES block:^(NSTimer * _Nonnull timer) {
// [self flashScrollIndicators];
[CATransaction begin];
[CATransaction setDisableActions:true];
[self flashScrollIndicators];
[CATransaction commit];
}];
} else {
// Fallback on earlier versions
}
[self.timer fire];
}
return self;
}
-(instancetype)init{
if (self=[super init]) {
self.tag = 836913;
if (@available(iOS 10.0, *)) {
self.timer=[NSTimer scheduledTimerWithTimeInterval:0.4 repeats:YES block:^(NSTimer * _Nonnull timer) {
[CATransaction begin];
[CATransaction setDisableActions:true];
[self flashScrollIndicators];
[CATransaction commit];
// [self flashScrollIndicators];
}];
} else {
// Fallback on earlier versions
}
[self.timer fire];
}
return self;
}
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
UIMenuController *menuController = [UIMenuController sharedMenuController];
if (menuController) {
[UIMenuController sharedMenuController].menuVisible = NO;
}
return NO;
}
-(void)flashScrollIndicators{
[super flashScrollIndicators];
// CATransaction *transition=[[CATransaction alloc] init];
// [transition begin];
if (self.scrollEnabled) {
[self showScrollBar];
}
}
-(void)showScrollBar{
NSLog(@"textTimer11111111");
for(UIView *img in [self subviews]){
if ([img isKindOfClass:[UIImageView class]] && img.autoresizingMask == UIViewAutoresizingFlexibleLeftMargin){
UIImageView *scollBar = (UIImageView *)img;
CGRect frame = scollBar.frame;
frame.origin.y = 0;
[scollBar setFrame:frame];
// NSLog(@"frameY====%f====frameX====%f====frameWith==%fandframeHeight==%f",frame.origin.y,frame.origin.x,frame.size.width,frame.size.height);
[scollBar setAlpha:1];
}
}
}
-(void)didMoveToWindow{
[super didMoveToWindow];
[self flashScrollIndicators];
}
@end