美文网首页
自定义的滑动进度条在tableView上滑动时产生卡顿

自定义的滑动进度条在tableView上滑动时产生卡顿

作者: 天亮説晚安 | 来源:发表于2016-01-21 15:59 被阅读697次

问题:自定义的进度条CustomProgressView在TaskSubmitViewController上滑动时发生卡顿,原因是在TaskSubmitViewController中水平滑动进度条的时候,可能会上下滚动该控制器上的tableView,所以使进度条产生卡顿。

解决办法:在自定义的进度条CustomProgressView中定义一个全局变量parentView,在TaskSubmitViewController中把全局变量myTableView赋给parentView,然后在CustomProgressView中对parentView进行控制,当进度条滑动时,禁止myTableView滚动;当当进度条滑动时,允许myTableView滚动。

屏幕快照 2016-01-21 下午4.33.49.png
//CustomProgressView.h文件
#import <UIKit/UIKit.h>
@interface CustomProgressView : UIView
//定义一个全局变量,接收传递过来的tableView
@property(nonatomic,strong) UIView *parentView;

@end
//CustomProgressView.m文件
#import "CustomProgressView.h"
#pragma mark - TouchEnevt
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{  
     if([_parentView isKindOfClass:[UITableView class] ]){
        ((UITableView *)_parentView).scrollEnabled =false;
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{   
    if([_parentView isKindOfClass:[UITableView class] ]){
        ((UITableView *)_parentView).scrollEnabled =true;
    }
}
//tableView.m文件
#import "TaskSubmitViewController.h"
@property (weak, nonatomic) IBOutlet UITableView *MyTableView;
@interface TaskSubmitViewController ()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate>

......
CustomProgressView * customProgressView = [[CustomProgressView alloc]init];
customProgressView.parentView = _MyTableView;         

相关文章

网友评论

      本文标题:自定义的滑动进度条在tableView上滑动时产生卡顿

      本文链接:https://www.haomeiwen.com/subject/cvblkttx.html