How to enable zoom for UICollectionView
I am not sure whether I got your question in correct way or not, but I think you might want to check these links:-
1. zoom entire UICollectionView - It also has a link to Sample code for UICollectionView. You might be interested in checking it.
2. Adding pinch zoom to a UICollectionView.
3. Make UICollectionView zoomable?
Hope this will help you.
How to do zoom in UICollectionView
You don't zoom a collection like you'd zoom a simple scroll view. Instead you should add a pinch gesture (or some other zoom mechanism) and use it to change the layout so your grid displays a different number of items in the visible part of the collection. This is basically changing the number of columns and thus the item size (cell size). When you update the layout the collection can animate between the different sizes, though it's highly unlikely you want a smooth zoom, you want it to go direct from N columns to N-1 columns in a step.
Make UICollectionView zoomable?
I think what you're asking for looks like what is done in the WWDC1012
video entitled Advanced Collection Views and Building Custom Layouts (demo starts at 20:20).
You basically have to add pinchGesture
to you UICollectionView
, then pass the pinch properties
(scale, center) to the UICollectionViewLayout
(which is a subclass
of UICollectionViewFlowLayout
), your layout will then perform the transformations
needed to zoom
on the desired cell.
How to zoom in the content of cell in uicollectionview
Just call this method when your collectionviewcell click
[self animateZoomforCell:cell]; // pass cell as collectionviewcell
-(void)animateZoomforCell:(UICollectionViewCell*)zoomCell
{
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
zoomCell.transform = CGAffineTransformMakeScale(1.6,1.6);
} completion:^(BOOL finished){
}];
}
-(void)animateZoomforCellremove:(UICollectionViewCell*)zoomCell
{
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
zoomCell.transform = CGAffineTransformMakeScale(1.0,1.0);
} completion:^(BOOL finished){
}];
}
How to zoom a UIScrollView inside of a UICollectionViewCell?
You might want to try manipulating the UIGestureRecognizers in order to do that. In the 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;
}
From Apple's documentation on UIView:
Attaching a gesture recognizer to a view defines the scope of the represented gesture, causing it to receive touches hit-tested to that view and all of its subviews. The view retains the gesture recognizer.
So you'll also want to make sure to remove them when the cell is not showing anymore.
- (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];
}
Since you're not modifying the UIGestureRecognizer's delegate, only its scope, it will still control the zooming of just that cell's scrollview.
EDIT:
I added the panGestureRecognizer
to the above examples, following a suggestion from the OP that it was needed. The zooming itself is completely handled by the pinchGestureRecognizer
, but it's true that in most cases, after zooming an image to a point where only a subset of it is visible, you'll want to pan to move the visible portion around. That is, it's part of a proper zooming experience.
Related Topics
Swiftui Buttonstyle - How to Check If Button Is Disabled or Enabled
Swift - Must Call a Designated Initializer of the Superclass Skspritenode Error
How to Animate an Svg Path in iOS
How to Handle Action Buttons in Push Notifications
Alphabetical Sections in Table Table View in Swift
iOS - Uisplitviewcontroller with Storyboard - Multiple Master Views and Multiple Detail Views
iOS 8 Nsinternalinconsistencyexception
Ios: How to Read an Audio File into a Float Buffer
How to Hide the Tabbar When Navigate with Navigationlink in Swiftui
Uitextfield Not Getting Keyboard Input
How to Get the MAC Os X Firewall to Permanently Allow My iOS App
Installed App from Testflight Crashes Due to Alleged Uisearchdisplaycontroller
Share Video on Twitter with Fabric API Without Composer iOS
Opening Testflight App from Another App and Deep Link to Specific App
Swiftui Transitions: Scale from Some Frame - Like iOS Homescreen Is Doing When Opening an App
How to Make Uipageviewcontroller Reuse Controller Like Tableview Reuse Cell