2017-07-18 10 views
0

UItableviewCell内でUIviewを左右にスワイプしたいのですが、これを実現するためにUIPanGestureRecognizerを使用しました。しかし、私がUItableviewをスクロールしようとしているとき、私のUiviewは上下に動くことができ、UItableviewcell、つまりSuperviewにスクロールできません。誰でも管理方法を教えてください。前もって感謝します?UItableviewcellのパンジェスチャー、スクロールでテーブルスクロールが機能しない

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

    return 10 

} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: "CardSwipeTVCell") as! CardSwipeTVCell 


    let tapGesture : UIPanGestureRecognizer! 
    tapGesture = UIPanGestureRecognizer(target: self, action: #selector(ViewController.tapEdit(_:))) 
    cell.cardView.addGestureRecognizer(tapGesture!) 
    cell.cardView.tag = indexPath.row 
    tapGesture!.delegate = self 


    cell.selectionStyle = .none 
    return cell 


} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 


} 

func tapEdit(_ recognizer: UIPanGestureRecognizer) 
{ 
    print(recognizer.view?.tag as Any) 

    let sender = recognizer.view?.tag as Any 

    let indexPath = IndexPath(row: sender as! Int, section: 0) 
    let cell = self.cardTableView.cellForRow(at: indexPath) as? CardSwipeTVCell 


    cell?.cardView.backgroundColor = UIColor.black 

    let card = recognizer.view! 
    let point = recognizer.translation(in: view) 
    card.center = CGPoint(x: (cell?.center.x)! + point.x, y: (cell?.center.y)! + point.y) 

    if recognizer.state == UIGestureRecognizerState.ended 
    { 
     UIView.animate(withDuration: 0.3, animations: { 

      card.center = (cell?.center)! 

     }) 

    } 

} 

また別の問題は、私のビューが消えてしまった2番目のセルをタップしたときですか?あなたの助けは本当に感謝します。

答えて

0
override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool { 
    if let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer { 
     //let translation = panGestureRecognizer.translation(in: superview!) 
     let translation = panGestureRecognizer.translationInView(superview) 
     if fabs(translation.x) > fabs(translation.y) { 
      return true 
     } 
     return false 
    } 
    return false 
} 

クラスに上記の委任メソッドを追加します。テーブルビュービューが垂直方向にスクロールしている間、それは幻覚を止めるでしょう。

関連する問題