标签:uitableview uiscrollview uibutton 高亮 延迟
估计很多码友都遇到过这样的情况:
UIButton在某些情况下不能立刻响应TouchDown事件,换句话说,迅速点击按钮时,你是永远看不见这个按钮的高亮状态的。
而你会发现,出现这种情况时,这些按钮都在UIScrollView(UITableView)上。NoDelayButtonScrollView.h:
#import <UIKit/UIKit.h> @interface NoDelayButtonScrollView : UIScrollView @end @interface NoDelayButtonTableView : UITableView @end
#import "NoDelayButtonScrollView.h"
@implementation NoDelayButtonScrollView
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.delaysContentTouches = NO;
}
return self;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
if ([view isKindOfClass:[UIButton class]])
{
return YES;
}
return [super touchesShouldCancelInContentView:view];
}
@end@implementation NoDelayButtonTableView
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.delaysContentTouches = NO;
// iterate over all the UITableView's subviews
for (id view in self.subviews)
{
// looking for a UITableViewWrapperView
if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewWrapperView"])
{
// this test is necessary for safety and because a "UITableViewWrapperView" is NOT a UIScrollView in iOS7
if([view isKindOfClass:[UIScrollView class]])
{
// turn OFF delaysContentTouches in the hidden subview
UIScrollView *scroll = (UIScrollView *) view;
scroll.delaysContentTouches = NO;
}
break;
}
}
}
return self;
}
- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
if ([view isKindOfClass:[UIButton class]])
{
return YES;
}
return [super touchesShouldCancelInContentView:view];
}
@endfor (id obj in cell.subviews)
{
if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewCellScrollView"])
{
UIScrollView *scroll = (UIScrollView *) obj;
scroll.delaysContentTouches = NO;
break;
}
}
标签:uitableview uiscrollview uibutton 高亮 延迟
原文地址:http://blog.csdn.net/youngsblog/article/details/44875267