Bạn có thể muốn thử thao tác UIGestureRecognizers để làm điều đó. Trong GalleryViewController
:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
GalleryImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"galleryImageCell" forIndexPath:indexPath];
ImageContext *imageContext = [self.images objectAtIndex:indexPath.row];
cell.imageContext = imageContext;
[self.collectionView addGestureRecognizer:cell.scrollView.pinchGestureRecognizer];
[self.collectionView addGestureRecognizer:cell.scrollView.panGestureRecognizer];
return cell;
}
Từ Apple's documentation on UIView:
Gắn một trình nhận dạng cử chỉ để một cái nhìn xác định phạm vi cử chỉ thể hiện, làm cho nó nhận được chạm lần truy cập thử nghiệm để xem điều đó và tất cả của nó các cuộc phỏng vấn. Chế độ xem giữ lại trình nhận dạng cử chỉ.
Vì vậy, bạn cũng sẽ muốn đảm bảo xóa chúng khi ô không hiển thị nữa.
- (void)collectionView:(UICollectionView *)collectionView
didEndDisplayingCell:(UICollectionViewCell *)cell
forItemAtIndexPath:(NSIndexPath *)indexPath {
// Get the cell instance and ...
[self.collectionView removeGestureRecognizer:cell.scrollView.pinchGestureRecognizer];
[self.collectionView removeGestureRecognizer:cell.scrollView.panGestureRecognizer];
}
Vì bạn không sửa đổi đại biểu của UIGestureRecognizer, chỉ phạm vi của nó, nó sẽ vẫn kiểm soát việc thu phóng chỉ cuộn của ô đó.
EDIT:
tôi thêm panGestureRecognizer
các ví dụ ở trên, sau đây là một gợi ý từ OP rằng nó là cần thiết. Bản thân việc thu phóng được xử lý hoàn toàn bởi pinchGestureRecognizer
, nhưng trong hầu hết các trường hợp, sau khi phóng to hình ảnh đến điểm chỉ hiển thị một tập hợp con, bạn sẽ muốn di chuyển phần có thể nhìn thấy xung quanh. Đó là, đó là một phần của trải nghiệm thu phóng thích hợp.
Cám ơn đã đưa mã cập nhật vào một repo. Nó rất hữu ích cho tôi! – super9