Reputation: 101
I have Collection view with horisontal flow, cells are heigh as sceen and width screen/4
So i want to add something like an animated transition so when you trying to expand the cell with two fingers this cell will expand its width until fingers reaches the sides of device, and as well some other stuff will animated as fingers are mooving.
So how can i track the fingers moove to call func in my vc with collection view and operate sizes of components and a cell. As well the expanding one particular cell width in cv so other cells will move away is a little trick to me.
Thanks for any help))
Upvotes: 2
Views: 997
Reputation: 2223
You can use the UIPinchGestureRecognizer to handle zoom using two fingers. By reading the zoom scale value of the view you can change the height and width of the cell then reload the cell.
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchWithGestureRecognizer:)];
[cell addGestureRecognizer:pinchGestureRecognizer];
Swift:
var pinchGestureRecognizer: UIPinchGestureRecognizer = UIPinchGestureRecognizer(target: self, action: Selector("handlePinchWithGestureRecognizer:"))
cell.addGestureRecognizer(pinchGestureRecognizer)
Read the zoom scale value and write your transform stuff here :
-(void)handlePinchWithGestureRecognizer:(UIPinchGestureRecognizer *)pinchGestureRecognizer{
self.cell.transform = CGAffineTransformScale(self.testView.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
}
Swift:
func handlePinchWithGestureRecognizer(sender: UIPinchGestureRecognizer)
{
sender.view!.transform = CGAffineTransformScale(sender.view!.transform,
sender.scale, sender.scale)
}
You can refer this also : https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/UIScrollView_pg/ZoomZoom/ZoomZoom.html
Upvotes: 1
Reputation: 1341
I would have loved to add this as a comment but I need 50 reputation to do it so be merciful with the down votes :P
You need to use UIViewControllerAnimatedTransitioning
, UIViewControllerTransitioningDelegate
, and UIPercentDrivenInteractiveTransition
.
You make an animated transition that uses the UICollectionViewCell's frame with respect to the ViewController, so you have to use the convertRect method with respect to the ViewController.view
The animated transition should add a screenshot of the NewViewController with the result of the convertRect method as its starting frame. Then the animation will be from the starting frame to the final frame of the NewViewController.
Test the animation and check if it has the desired result. Then implement
the UIPercentDrivenInteractiveTransition
and tie it to a UIPinchGestureRecognizer
. I'd suggest adding the pinch gesture to each cell and then creating a delegate for cell, and set the UIPercentDrivenInteractiveTransition
as the delegate for it that implements a function func userDidUsePinchGesture(gesture: UIPinchGestureRecognizer)
. In that function you can calculate the percentage of the completion of the transition.
I'm sorry if this wall of text is a bit intimidating, and I hope that this helps you out. If you haven't implemented UIViewControllerAnimatedTransitioning
, UIViewControllerTransitioningDelegate
, and UIPercentDrivenInteractiveTransition
before I suggest that you check out this tutorial Creating Custom UIViewController Transitions
Upvotes: 0