2014-07-11 2 views
0

UIPanGestureRecognizer으로 사용자 정의 스 와이프 가능 UICollectionViewCell을 만들려고합니다. (내 UICollectionViewCell에 걸쳐으로 스 와이프하면, 프레임이 올바른 변화를 기록프레임 업데이트시 UICollectionViewCell이 변경되지 않습니다.

func attributesForCell(cell: SwipeableCollectionViewCell) -> UICollectionViewLayoutAttributes { 
    let indexPath = collectionView.indexPathForCell(cell) 
    return collectionView.layoutAttributesForItemAtIndexPath(indexPath) 
} 

다음 UICollectionViewController (셀의 위임)에서

func setup() { 
    attributes = delegate.attributesForCell(self) 
    selectionView = UIView(frame: attributes.frame) 
    self.addSubview(selectionView) 
    let cellPan = UIPanGestureRecognizer(target: self, action: "cellDidPan:") 
    selectionView.addGestureRecognizer(cellPan) 
} 

func cellDidPan(gesture: UIPanGestureRecognizer) { 
    switch gesture.state { 
    case .Began: 
     originalFrame = attributes.frame 
    case .Changed: 
     let translation: CGPoint = gesture.translationInView(selectionView) 
     attributes.frame = CGRect(origin: CGPoint(x: originalFrame.origin.x + translation.x, y: originalFrame.origin.y), size: originalFrame.size) 
     println("t \(translation.x)") 
     println("c \(attributes.center)") 
     println("f \(attributes.frame)") 
    case .Ended: 
     println("nothing here yet") 
    default: 
     println("Unrecognized gesture state") 
    } 
} 

: 사용자 정의 UICollectionViewCell에서

: 여기에 내 코드입니다 모든 것은 x 좌표를 제외하고는 동일하게 유지됩니다. x 좌표는 더 작은 왼쪽으로 스 와이프되고 오른쪽은 더 크게 스 와이프됩니다.) 그러나 셀은 동일한 위치에 그대로 있습니다.

나는 UICollectionViewFlowLayout을 사용 중이며 스토리 보드 및 Interface Builder에서 모든 것을 설정하고 있습니다.

+0

질문에 대한 답변을 찾은 경우 답변을 작성하여 좋은 세부 정보를 제공하여 향후 다른 사용자가 같은 문제를 겪을 때 도움이됩니다. – Neeku

답변

0

답변을 찾았습니다! layoutAttributesForItemAtIndexPath()는 실제 속성 객체가 아닌 사본의 사본을 반환합니다. 즉,이 속성을 수정하면 아무 것도하지 않습니다. 대신 UICollectionViewCell 속성을 사용하십시오.

관련 문제