Keep UICollectionViewCell centered after Zooming with UIPinchGestureRecognizer

痞子三分冷 提交于 2020-01-03 02:51:05

问题


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:

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

来源:https://stackoverflow.com/questions/23269622/keep-uicollectionviewcell-centered-after-zooming-with-uipinchgesturerecognizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!