添加消息长按弹窗

This commit is contained in:
2026-02-03 15:53:07 +08:00
parent d482cfcb7d
commit a0923c8572
6 changed files with 368 additions and 1 deletions

View File

@@ -42,6 +42,7 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
@property (nonatomic, strong) UILabel *topStatusLabel;
@property (nonatomic, assign) BOOL isTopLoading;
@property (nonatomic, assign) BOOL isTopNoMore;
@property (nonatomic, strong) UILongPressGestureRecognizer *messageLongPressGesture;
@end
@@ -101,6 +102,13 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
make.edges.equalTo(self);
}];
//
self.messageLongPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(handleMessageLongPress:)];
self.messageLongPressGesture.minimumPressDuration = 0.4;
self.messageLongPressGesture.cancelsTouchesInView = YES;
[self.tableView addGestureRecognizer:self.messageLongPressGesture];
// contentInset
self.contentBottomInset = 0;
[self updateContentBottomInset:self.contentBottomInset];
@@ -136,6 +144,32 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
*/
}
#pragma mark - Long Press
- (void)handleMessageLongPress:(UILongPressGestureRecognizer *)gesture {
if (gesture.state != UIGestureRecognizerStateBegan) {
return;
}
CGPoint point = [gesture locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
if (!indexPath || indexPath.row >= self.messages.count) {
return;
}
KBAiChatMessage *message = self.messages[indexPath.row];
if (!message || message.isLoading || message.type == KBAiChatMessageTypeTime) {
return;
}
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
CGRect cellRect = cell ? [cell convertRect:cell.bounds toView:nil] : CGRectZero;
if ([self.delegate respondsToSelector:@selector(chatTableView:didLongPressMessage:sourceRect:)]) {
[self.delegate chatTableView:self didLongPressMessage:message sourceRect:cellRect];
}
}
#pragma mark - Public Methods
- (void)setInverted:(BOOL)inverted {