ios - UITableViewCell setHighlighted:(BOOL)highlighted 始终为 false
问题描述
我正在重写UITableViewCell
类以向我的单元格添加波纹/墨水效果。基于 iOS Material Component List,我唯一应该做的就是像这样覆盖 setHighlighted 方法:
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
if (highlighted) {
[self startInk];
} else {
[self endInk];
}
}
这种技术适用,UICollectionViewCell
但我不确定它是否应该适用于UITableViewCell
.
每当我推动单元格并且我没有抬起手指时,这个方法永远不会被调用。只有在何时被跟注并加注并且highlighted
总是false
。
任何人都知道如何覆盖这个长按开始动画?
提前谢谢你!
解决方案
我终于通过覆盖 (void)touchesBegan:withEvent: 方法得到它。这是我基于 iOS Material Component List的代码:
@property(strong, nonatomic, nonnull) MDCInkView *inkView;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
self.lastTouch = location;
if (self.selectionStyle != UITableViewCellSelectionStyleNone){
NSInteger selectionStyle = self.selectionStyle;
self.selectionStyle = UITableViewCellSelectionStyleNone;
[UIView animateWithDuration:0.25f
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self startInk];
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.25f
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[self endInk];
}completion:^(BOOL finished) {
self.selectionStyle = selectionStyle;
}];
}];
}
[super touchesBegan:touches withEvent:event];
}
- (void)startInk {
[self.inkView startTouchBeganAtPoint:_lastTouch animated:YES withCompletion:nil];
}
- (void)endInk {
[self.inkView startTouchEndAtPoint:_lastTouch animated:YES withCompletion:nil];
}
推荐阅读
- javascript - 单击标题时jQuery上下滑动ul
- javascript - HTML 向 PHP 后端发送消息并检查响应
- spring-boot - 如何在 graphql-spqr-spring-boot-starter 中禁用模式自省
- core-data - 使用公共 CloudKit 数据库 (NSPersistentCloudkitContainer) - macOS
- android - 是否有用于在 Android 上添加语言的 ADB 命令?
- javascript - 使用 TypeScript 和 Axios 进行 http 调用时如何选择响应正文中的某些字段
- php - Codeigniter URL 中的双斜杠问题
- time-complexity - 哈希表时间复杂度混淆
- html - 如何通过xpath在第一个子节点之前获取节点的文本?
- amazon-web-services - 查找 executionRoleArn、taskRoleArn 的值