Keep UICollectionViewCell centered after Zooming w

2019-05-29 08:11发布

I'm having this issue. I change the scale and as well the transition of the view of a UICollectionViewCell, for doing zoom in the position of my fingers do the UIPinchGesture. But after that, the position of the view changes and the view go off the screen and its bounds. I want that the Gesture View get back to its correct position.

This is what is happening:

enter image description here

I have tried to assign a CGAffineTransformIdentity to the view if the center of the cell changes, but after the Scale and the Translate, its center always changes, so its frame as well.

The code in UIGestureRecognizerStateEnded:

    if ([gesture state] == UIGestureRecognizerStateEnded){

       //Get the Cell that is getting zoomed
       CGPoint initialPinchPoint = [gesture locationInView:self.collectionView];

       NSIndexPath* pinchedCellPath = [self.collectionView indexPathForItemAtPoint:initialPinchPoint];

       SBQPhotosDetailCollectionViewCell *cell=[[SBQPhotosDetailCollectionViewCell alloc] init];

       cell=(SBQPhotosDetailCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:pinchedCellPath];

       //Check ifs frame with the gesture of the Pinch
       if ((cell.frame.origin.x != [gesture view].frame.origin.x) || (cell.frame.origin.y  != [gesture view].frame.origin.y)){

          [gesture view].transform = CGAffineTransformIdentity;
       }
    }

I would like to apply the CGAffineTransformIdentity only if the view of the Gesture change its center, position, but not if the view got zoomed.

Thanks

0条回答
登录 后发表回答