Ios UITableViewCell中的UIButton不';不要在水龙头上突出显示
问题:当用户点击UITableViewCell中的UIButton时,该按钮只会在长时间点击时高亮显示,而不会在快速点击时高亮显示。无论轻触持续时间如何,此按钮都将高亮显示所需的行为 不幸的是:在任何UIScrollView或UITableView上都不能将delaysContentTouches设置为“否”,因为还有其他不必要的副作用Ios UITableViewCell中的UIButton不';不要在水龙头上突出显示,ios,iphone,objective-c,ipad,uibutton,Ios,Iphone,Objective C,Ipad,Uibutton,问题:当用户点击UITableViewCell中的UIButton时,该按钮只会在长时间点击时高亮显示,而不会在快速点击时高亮显示。无论轻触持续时间如何,此按钮都将高亮显示所需的行为 不幸的是:在任何UIScrollView或UITableView上都不能将delaysContentTouches设置为“否”,因为还有其他不必要的副作用 那么:我该如何解决这个问题-有没有办法绕过delaysContentTouches值,将触控转发到按钮?在原型单元格中将按钮的标签设置为“1” 在cellFor
那么:我该如何解决这个问题-有没有办法绕过delaysContentTouches值,将触控转发到按钮?在原型单元格中将按钮的标签设置为“1” 在cellForRowAtIndexPath中,应将UIButton链接到一个方法:
UIButton *button = (UIButton *)[cell viewWithTag:1];
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside];
然后,在该方法中,您只需执行以下操作:
-(void) aMethod: (id) sender{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.cartTableView];
NSIndexPath *indexPath = [self.cartTableView indexPathForRowAtPoint:buttonPosition];
if (indexPath != nil)
{
//Do your stuff
}
}
这不会在运行代码之前增加任何延迟 您需要创建一个UIButton类别(或者子类,如果您不想影响所有其他按钮的话),并在ToucheSStart中设置highlight=YES 请参阅中的代码以获取示例实现。这对我来说很有用:
@weakify(self);
[self.publishButton bk_addEventHandler:^(id sender) {
@strongify(self);
if (self.clickBlock) {
self.clickBlock(self.draftModel);
}
[UIView animateWithDuration:0.1 animations:^{
self.publishButton.backgroundColor = [UIColor whiteColor];
}];
} forControlEvents:UIControlEventTouchUpInside];
[self.publishButton bk_addEventHandler:^(id sender) {
self.publishButton.backgroundColor = [UIColor redColor];
} forControlEvents:UIControlEventTouchDown];
使用主线程
dispatch_async(dispatch_get_main_queue(), ^{
});
只需将
delayContentTouchs=false
设置为您正在使用的任何滚动视图(UITableView或UICollectionView)。应该这样做
正如医生所说:
一个布尔值,用于确定滚动视图是否延迟触摸手势的处理。
如果此属性的值为true,则滚动视图会延迟处理触摸手势,直到它能够确定滚动是否是目的。如果该值为false,则滚动视图会立即调用touchesshouldbeagin(:with:in:)。默认值为true
OP询问如何在快速点击时突出显示按钮。你的建议不起作用。