半年不動(dòng)的代碼產(chǎn)品說有問題,原因是 UISlider 滑動(dòng)不靈敏,要手指先觸摸一下媚朦,按上去才能滑動(dòng)。場(chǎng)景是 <code>UISlider</code> 添加在了<code>UITableViewCell</code> 上日戈。
因?yàn)轫?xiàng)目中是繼承了 <code>UISlider</code> 询张,所以,很簡(jiǎn)單的解決方案浙炼,在項(xiàng)目中份氧,把UISlider 從新生成一個(gè),放在一個(gè)什么事件都不處理的 <code>UIView</code> 上鼓拧“牖穑看看效果。結(jié)果很流暢季俩。所以問題肯定出在<code>UITableView</code> 或者 <code>UITableViewCell</code> 上。
查看UITableView 以及 UIScrollView 的文檔梅掠。
@property(nonatomic) BOOL delaysContentTouches; // default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses
發(fā)現(xiàn) delaysContentTouches 屬性酌住。默認(rèn)為YES店归, 如果設(shè)置為NO ,會(huì)立即響應(yīng) touchesShouldBegin 方法。酪我。消痛。
解決方案
_tableView.delaysContentTouches = NO;
[_tableView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[UIScrollView class]]) {
UIScrollView *_s = (UIScrollView *)obj;
_s.delaysContentTouches = NO;
}
}];
關(guān)閉掉<code>tableview</code> 所有的 <code>delaysContentTouches</code> 方法。
后來測(cè)試說都哭,在iOS7上還是不靈敏秩伞。。嗯哼欺矫?經(jīng)過測(cè)試iOS7 UITableViewCell 上的scrollView 也會(huì)開啟纱新,所以在創(chuàng)建cell 的時(shí)候,用同樣的手段穆趴,脸爱,
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self setup];
///#FIX iOS7 滑動(dòng)不靈敏
for (UIView *view in self.subviews) {
if([view isKindOfClass:[UIScrollView class]]) {
((UIScrollView *)view).delaysContentTouches = NO;
break;
}
}
}
return self;
}
OK 萬事大吉。未妹。簿废。