Ios CollectionViewCell无法使用挤压手势正常工作

Ios CollectionViewCell无法使用挤压手势正常工作,ios,swift,gesture,pinch,Ios,Swift,Gesture,Pinch,我正在使用一个CollectionView和一个连接到CVCell的捏手势。 我有一个图像在细胞和捏手势放大和缩小的图像。我的问题是,捏手势只适用于偶数行,而不适用于奇数行。我的意思是,对于第一个单元格,我不能放大图片,我可以放大第二个单元格的图片,不能放大第三个单元格,可以放大第四个单元格,就像这样。我找不到合乎逻辑的解释。也许你能看到我错过了什么。提前谢谢。我的代码在这里: @IBAction func handlePinch(recognizer : UIPinchGestureRecog

我正在使用一个
CollectionView
和一个连接到
CVCell
的捏手势。 我有一个图像在细胞和捏手势放大和缩小的图像。我的问题是,捏手势只适用于偶数行,而不适用于奇数行。我的意思是,对于第一个单元格,我不能放大图片,我可以放大第二个单元格的图片,不能放大第三个单元格,可以放大第四个单元格,就像这样。我找不到合乎逻辑的解释。也许你能看到我错过了什么。提前谢谢。我的代码在这里:

@IBAction func handlePinch(recognizer : UIPinchGestureRecognizer) {
    if let view = recognizer.view {
        view.transform = CGAffineTransformScale(view.transform,
            recognizer.scale, recognizer.scale)
        recognizer.scale = 1
    }
}

@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
    super.viewDidLoad()
    var b = UIBarButtonItem(barButtonSystemItem: .Bookmarks, target: self, action: "barButton")
    self.navigationItem.rightBarButtonItem = b
    var ItemIndex = NSIndexPath(forItem: catchNumber, inSection: 0)
    self.collectionView?.scrollToItemAtIndexPath(ItemIndex, atScrollPosition: UICollectionViewScrollPosition.CenteredHorizontally, animated: false)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

func barButton(){
    let alert = UIAlertController(title: "Select an option", message: " ", preferredStyle: UIAlertControllerStyle.ActionSheet)
    let shareButton = UIAlertAction(title: "Share", style: UIAlertActionStyle.Default) { (alert) -> Void in
        let content = FBSDKSharePhotoContent()
        let photo : FBSDKSharePhoto = FBSDKSharePhoto()
        photo.image = self.image
        photo.userGenerated = true
        content.photos = [photo]
        FBSDKMessageDialog.showWithContent(content, delegate:nil)
    }
    let saveButton = UIAlertAction(title: "Save", style: UIAlertActionStyle.Default) { (alert) -> Void in
        UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil)
    }
    let deleteButton = UIAlertAction(title: "Delete", style: UIAlertActionStyle.Default) { (alert) -> Void in
        var tmp = self.catchPictures[self.catchNumber].componentsSeparatedByString("_")
        self.idDelete = tmp[1]
        let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "/\(self.idDelete)", parameters: nil , HTTPMethod: "DELETE")
        graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
            if (error == nil){
                self.navigationController?.popViewControllerAnimated(true)
            }else{
                let alertController = UIAlertController(title: "Delete Error", message:
                    "An error occured while deleting photo", preferredStyle: UIAlertControllerStyle.Alert)
                alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default,handler: nil))

                self.presentViewController(alertController, animated: true, completion: nil)
            }

        })
    }
    let cancelButton = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (alert) -> Void in
        println("Cancel Pressed")
    }
    alert.addAction(shareButton)
    alert.addAction(saveButton)
    alert.addAction(deleteButton)
    alert.addAction(cancelButton)
    self.presentViewController(alert, animated: true, completion: nil)
}

func collectionView(collectionView: UICollectionView, numberOfSectionInCollectionView section: Int) -> Int {
    return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return catchPictures.count

}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    var cell = collectionView.dequeueReusableCellWithReuseIdentifier("PhotoCell", forIndexPath: indexPath) as! UICollectionViewCell
    let a:UIImageView = cell.contentView.viewWithTag(1) as! UIImageView
    dispatch_async(dispatch_get_main_queue(),{
        var urlString: NSString = self.catchPictures[indexPath.row] as NSString
        var imgURL: NSURL = NSURL(string: urlString as String)!
        var request: NSURLRequest = NSURLRequest(URL: imgURL)
        var urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)!
        NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
            if !(error != nil) {
                var image = UIImage(data: data)
                a.image = image
                self.image = a.image
            }})

        self.flowLayout.minimumInteritemSpacing = 0.0
        self.flowLayout.minimumLineSpacing = 0.0
        self.flowLayout.itemSize = CGSizeMake(self.view.frame.width, 350)
        self.flowLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
        self.collectionView.setCollectionViewLayout(self.flowLayout, animated: true)
    })
    self.catchNumber = indexPath.row
    return cell
}

不,不,没有定制的CVCell,是我的错误,我把CVCell写成CollectionViewCell的缩写,从代码中可以看出,我没有使用任何定制的collection view cell;)很抱歉误解

您能发布自定义集合视图单元格吗
CVCell
no没有自定义CVCell,我的错误是,我将CVCell写为CollectionViewCell的缩写,在代码中可以看到,我没有使用任何自定义集合视图单元格;)抱歉,误解了将挤压识别器添加到集合视图的代码在哪里?我在storyborad上添加挤压手势作为一个组件,但我在添加代码时修复了该问题;)非常感谢。