Tôi đang cố gắng để có được vị trí cảm ứng bên trong UICollectionviewCell đã chọn. Tôi có một UIViewController, vc, chứa một UICollectionView, collectionView, như là khung nhìn của nó. Bên trong collectionView là UICollectionViewCells. Các vc phù hợp với các UICollectionViewDelegate
tốt nhất là tôi muốn có được vị trí xúc động bên trong gọi lại đại biểu, collectionView:(UICollectionView *)collection didSelectItemAtIndexPath:(NSIndexPath *)indexPath
, (nếu có thể). Bất kỳ đề xuất về cách làm điều đó? Cảm ơn.liên lạc với vị trí của uicollectionviewcell
+--------------------------------------------+
| UICollectionView |
| |
| +-------------+ +-------------+ |
| | UICollec | | | |
| | tionView | | | |
| | Cell | | *<---------------<Touch here
| | | | | |
| +-------------+ +-------------+ |
| |
+--------------------------------------------+
* CẬP NHẬT * tôi đã kết thúc phát hiện vòi nước trên UIViewCollectionView
sử dụng UIGestureRecognizer
và sau đó chuyển đổi điểm tap vào xem UICollectionViewCell
. Vui lòng cho tôi biết nếu có cách nào tốt hơn. Cảm ơn.
-(void) viewDidLoad {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tapGesture setNumberOfTapsRequired:1];
[self.collectionView addGestureRecognizer:tapGesture];
}
-(void) handleTap:(UIGestureRecognizer*) gesture {
if (gesture.state == UIGestureRecognizerStateEnded) {
CGPoint tappedPoint = [gesture locationInView:_collectionView];
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:tappedPoint];
CollectionViewCell *cell = (CollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
CGPoint pointWRTCell = [cell convertPoint:tappedPoint fromView:self.collectionView];
NSLog(@"collectionView point(%1.1f,%1.1f); cell point (%1.1f,%1.1f)",
tappedPoint.x,tappedPoint.y,pointWRTCell.x,pointWRTCell.y);
}
}
Cảm ơn bạn đã trả lời. "UICollectionView" của lớp con có thể hoạt động. Tôi đã kết thúc bằng cách sử dụng 'UITabGestureRecognizer' và chuyển đổi vị trí khai thác từ 'UICollectionView' thành 'UICollectionViewCell' – Loozie
Một số ngữ cảnh có thể giúp chúng tôi đưa ra giải pháp tốt hơn. Vấn đề bạn đang cố gắng giải quyết là gì? – CrimsonChris
Tôi chỉ đơn giản muốn xóa một ô khi một người dùng tab một vị trí cụ thể của một tế bào (không phải là chính tế bào) – Loozie