使用UIPinchGestureRecognizer进行缩放后,保持UICollectionViewCell居中

时间:2014-04-24 12:57:52

标签: uicollectionview uigesturerecognizer uicollectionviewcell cgaffinetransform uipinchgesturerecognizer

我遇到了这个问题。我改变了比例以及UICollectionViewCell视图的转换,为了放大我的手指的位置做UIPinchGesture。但在那之后,视图的位置会发生变化,视图会脱离屏幕及其边界。我希望手势视图回到正确的位置。

这就是发生的事情:

enter image description here

如果单元格的中心发生更改,我尝试为视图指定CGAffineTransformIdentity,但在ScaleTranslate之后,其中心始终会更改,因此其frame 1}}。

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;
       }
    }

我希望仅在CGAffineTransformIdentity的视图更改其Gesturecenter时才应用position,但如果view获得{{} {1}}。

由于

0 个答案:

没有答案