File tree Expand file tree Collapse file tree 5 files changed +94
-4
lines changed
JSQMessagesViewController Expand file tree Collapse file tree 5 files changed +94
-4
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,8 @@ - (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collection
405
405
406
406
#pragma mark - JSQMessages collection view flow layout delegate
407
407
408
+ #pragma mark - Adjusting cell label heights
409
+
408
410
- (CGFloat)collectionView : (JSQMessagesCollectionView *)collectionView
409
411
layout : (JSQMessagesCollectionViewFlowLayout *)collectionViewLayout heightForCellTopLabelAtIndexPath : (NSIndexPath *)indexPath
410
412
{
@@ -452,10 +454,27 @@ - (CGFloat)collectionView:(JSQMessagesCollectionView *)collectionView
452
454
return 0 .0f ;
453
455
}
454
456
457
+ #pragma mark - Responding to collection view tap events
458
+
455
459
- (void )collectionView : (JSQMessagesCollectionView *)collectionView
456
460
header : (JSQMessagesLoadEarlierHeaderView *)headerView didTapLoadEarlierMessagesButton : (UIButton *)sender
457
461
{
458
462
NSLog (@" Load earlier messages!" );
459
463
}
460
464
465
+ - (void )collectionView : (JSQMessagesCollectionView *)collectionView didTapAvatarImageView : (UIImageView *)avatarImageView atIndexPath : (NSIndexPath *)indexPath
466
+ {
467
+ NSLog (@" Tapped avatar!" );
468
+ }
469
+
470
+ - (void )collectionView : (JSQMessagesCollectionView *)collectionView didTapMessageBubbleAtIndexPath : (NSIndexPath *)indexPath
471
+ {
472
+ NSLog (@" Tapped message bubble!" );
473
+ }
474
+
475
+ - (void )collectionView : (JSQMessagesCollectionView *)collectionView didTapCellAtIndexPath : (NSIndexPath *)indexPath touchLocation : (CGPoint)touchLocation
476
+ {
477
+ NSLog (@" Tapped cell at %@ !" , NSStringFromCGPoint(touchLocation));
478
+ }
479
+
461
480
@end
Original file line number Diff line number Diff line change @@ -516,6 +516,19 @@ - (void)messagesCollectionViewCellDidTapAvatar:(JSQMessagesCollectionViewCell *)
516
516
atIndexPath: [self .collectionView indexPathForCell: cell]];
517
517
}
518
518
519
+ - (void )messagesCollectionViewCellDidTapMessageBubble : (JSQMessagesCollectionViewCell *)cell
520
+ {
521
+ [self .collectionView.delegate collectionView: self .collectionView
522
+ didTapMessageBubbleAtIndexPath: [self .collectionView indexPathForCell: cell]];
523
+ }
524
+
525
+ - (void )messagesCollectionViewCellDidTapCell : (JSQMessagesCollectionViewCell *)cell atPosition : (CGPoint)position
526
+ {
527
+ [self .collectionView.delegate collectionView: self .collectionView
528
+ didTapCellAtIndexPath: [self .collectionView indexPathForCell: cell]
529
+ touchLocation: position];
530
+ }
531
+
519
532
#pragma mark - Input toolbar delegate
520
533
521
534
- (void )messagesInputToolbar : (JSQMessagesInputToolbar *)toolbar didPressLeftBarButton : (UIButton *)sender
Original file line number Diff line number Diff line change 208
208
didTapAvatarImageView : (UIImageView *)avatarImageView
209
209
atIndexPath : (NSIndexPath *)indexPath ;
210
210
211
+ /* *
212
+ * Notifies the delegate that the message bubble at the specified indexPath did receive a tap event.
213
+ *
214
+ * @param collectionView The collection view object that is notifying you of the tap event.
215
+ * @param indexPath The index path of the item for which the message bubble was tapped.
216
+ */
217
+ - (void )collectionView : (JSQMessagesCollectionView *)collectionView didTapMessageBubbleAtIndexPath : (NSIndexPath *)indexPath ;
218
+
219
+ /* *
220
+ * Notifies the delegate that the cell at the specified indexPath did receive a tap event at the specified touchLocation.
221
+ *
222
+ * @param collectionView The collection view object that is notifying you of the tap event.
223
+ * @param indexPath The index path of the item for which the message bubble was tapped.
224
+ * @param touchLocation The location of the touch event in the cell's coordinate system.
225
+ *
226
+ * @warning This method is *only* called if position is *not* within the bounds of the cell's
227
+ * avatar image view or message bubble image view. In other words, this method is *not* called when the cell's
228
+ * avatar or message bubble are tapped. There are separate delegate methods for these two cases.
229
+ *
230
+ * @see `collectionView:didTapAvatarImageView:atIndexPath:`
231
+ * @see `collectionView:didTapMessageBubbleAtIndexPath:atIndexPath:`
232
+ */
233
+ - (void )collectionView : (JSQMessagesCollectionView *)collectionView
234
+ didTapCellAtIndexPath : (NSIndexPath *)indexPath
235
+ touchLocation : (CGPoint)touchLocation ;
236
+
211
237
/* *
212
238
* Notifies the delegate that the collection view's header did receive a tap event.
213
239
*
Original file line number Diff line number Diff line change 31
31
@required
32
32
33
33
/* *
34
- * Tells the delegate that the avatarImageView of a cell has been tapped.
34
+ * Tells the delegate that the avatarImageView of the cell has been tapped.
35
35
*
36
- * @param cell The cell that received the tap.
36
+ * @param cell The cell that received the tap touch event .
37
37
*/
38
38
- (void )messagesCollectionViewCellDidTapAvatar : (JSQMessagesCollectionViewCell *)cell ;
39
39
40
+ /* *
41
+ * Tells the delegate that the message bubble of the cell has been tapped.
42
+ *
43
+ * @param cell The cell that received the tap touch event.
44
+ */
45
+ - (void )messagesCollectionViewCellDidTapMessageBubble : (JSQMessagesCollectionViewCell *)cell ;
46
+
47
+ /* *
48
+ * Tells the delegate that the cell has been tapped at the point specified by position.
49
+ *
50
+ * @param cell The cell that received the tap touch event.
51
+ * @param position The location of the received touch in the cell's coordinate system.
52
+ *
53
+ * @discussion This method is *only* called if position is *not* within the bounds of the cell's
54
+ * avatar image view or message bubble image view. In other words, this method is *not* called when the cell's
55
+ * avatar or message bubble are tapped.
56
+ *
57
+ * @see `messagesCollectionViewCellDidTapAvatar:`
58
+ * @see `messagesCollectionViewCellDidTapMessageBubble:`
59
+ */
60
+ - (void )messagesCollectionViewCellDidTapCell : (JSQMessagesCollectionViewCell *)cell atPosition : (CGPoint)position ;
61
+
40
62
@end
41
63
42
64
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ - (void)awakeFromNib
131
131
self.longPressGestureRecognizer = longPress;
132
132
133
133
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (jsq_handleTapGesture: )];
134
- [self .avatarContainerView addGestureRecognizer: tap];
134
+ [self addGestureRecognizer: tap];
135
135
self.tapGestureRecognizer = tap;
136
136
}
137
137
@@ -363,7 +363,17 @@ - (void)jsq_handleLongPressGesture:(UILongPressGestureRecognizer *)longPress
363
363
364
364
- (void )jsq_handleTapGesture : (UITapGestureRecognizer *)tap
365
365
{
366
- [self .delegate messagesCollectionViewCellDidTapAvatar: self ];
366
+ CGPoint touchPt = [tap locationInView: self ];
367
+
368
+ if (CGRectContainsPoint (self.avatarContainerView .frame , touchPt)) {
369
+ [self .delegate messagesCollectionViewCellDidTapAvatar: self ];
370
+ }
371
+ else if (CGRectContainsPoint (self.messageBubbleContainerView .frame , touchPt)) {
372
+ [self .delegate messagesCollectionViewCellDidTapMessageBubble: self ];
373
+ }
374
+ else {
375
+ [self .delegate messagesCollectionViewCellDidTapCell: self atPosition: touchPt];
376
+ }
367
377
}
368
378
369
379
#pragma mark - Notifications
You can’t perform that action at this time.
0 commit comments