0

iOS通知センターの行に似た行の編集アクションでtableviewを作成する必要があります。
私がこれまで使用してきたリソースは、編集アクションの背景色と幅のみを編集できると言っています。私が望むのは、iOS Notifications Centerの通知のようなカスタムの外観です。iOS通知センターに似たテーブルビューでのアクションの編集

注釈部分を参照してください。これは私が欲しいものです。

See the annotated portion

これは私がこれまで管理してきたものです。|

This is what I have managed so far :|

すべてのヘルプ/指導をいただければ幸いです!
ありがとうございます!

+0

あなたのように画像を使用してみました:: 'action.backgroundColor = UIColor(patternImage:UIImage(命名:! "rowActionPic"))私は' – D4ttatraya

+0

@DashAndRest

結果がこれです。 ...うーん...あなたは私の行の背景が実際の行の高さよりもわずかに小さいのを見ていますか?それで何が起こったのか、私がpatternImageを使うと(そして私もroundedCornersを設定してiOSの通知センターの外観を達成した)、私は反復的な画像をもう一つ下に置いた。また、色を変更する方法も分からなかった各アクションのテキストの数:| –

+0

スワイプアクションを追加するためのカスタムライブラリがあります。コードを見て必要な部分を変更することができます。 – Losiowaty

答えて

0

私は

...テーブルビューセルの一部として、私自身のビューを作成し、カスタムアニメーションを追加することになったサンプルコード:私のtableViewControllerで
:私のテーブルで

override func viewDidLoad() { 
    super.viewDidLoad() 
    .... 

    let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(handleTap)) 
    tableView.addGestureRecognizer(tapGesture) 

    let leftSwipeGesture = UISwipeGestureRecognizer.init(target: self, action: #selector(handleLeftSwipe(_:))) 
    leftSwipeGesture.direction = .left 
    tableView.addGestureRecognizer(leftSwipeGesture) 

    let rightSwipeGesture = UISwipeGestureRecognizer.init(target: self, action: #selector(handleRightSwipe(_:))) 
    rightSwipeGesture.direction = .right 
    tableView.addGestureRecognizer(rightSwipeGesture) 
} 

func handleTap(_ gestureRecognizer: UISwipeGestureRecognizer) { 
    let point = gestureRecognizer.location(in: self.tableView) 
    if let indexPath = self.tableView.indexPathForRow(at: point) { 
     var shouldSelectRow = false 
     if indexPathBeingEdited != nil { 
      if indexPath == indexPathBeingEdited { 
       shouldSelectRow = true 
      } else { 
       //handle close of the cell being edited already 
       if let previousEditedCell = tableView.cellForRow(at: indexPathBeingEdited!) as? NotificationCenterTableViewCell { 
        previousEditedCell.closeEditActions() 
        indexPathBeingEdited = nil 
       } 
      } 
     } else { 
      shouldSelectRow = true 
     } 
     if shouldSelectRow { 
      tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle) 
      tableView(tableView, didSelectRowAt: indexPath) 
     } 
    } 
} 

func handleLeftSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) { 
    let point = gestureRecognizer.location(in: self.tableView) 
    if let indexPath = self.tableView.indexPathForRow(at: point) { 
     if indexPathBeingEdited != nil { 
      if indexPath == indexPathBeingEdited { 
       //Do nothing 
      } else { 
       //handle close of the cell being edited already 
       if let previousEditedCell = tableView.cellForRow(at: indexPathBeingEdited!) as? NotificationCenterTableViewCell { 
        previousEditedCell.closeEditActions() 
        indexPathBeingEdited = nil 
       } 
      } 
     } 
     //proceed with left swipe action 
     if let cell = tableView.cellForRow(at: indexPath) as? NotificationCenterTableViewCell { 
      cell.handleLeftSwipe(gestureRecognizer) 
      let notification = notificationsArray[indexPath.section].notificationItems[indexPath.row] 

      //Update the title of Read button 
      if notification.isNotificationRead { 
       cell.readUnreadButtonLabel.text = "Unread" 
      } else { 
       cell.readUnreadButtonLabel.text = "Read" 
      } 
      indexPathBeingEdited = indexPath 
     } 
    } 
} 

func handleRightSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) { 
    let point = gestureRecognizer.location(in: self.tableView) 
    if let indexPath = self.tableView.indexPathForRow(at: point) { 
     if indexPathBeingEdited != nil { 
      if indexPath == indexPathBeingEdited { 
       if let cell = tableView.cellForRow(at: indexPath) as? NotificationCenterTableViewCell { 
        cell.closeEditActions() 
        indexPathBeingEdited = nil 
        //Update the title of Read button 
        cell.readUnreadButtonLabel.text = "Read" 
       } 
      } else { 
       //handle close of the cell being edited already 
       if let previousEditedCell = tableView.cellForRow(at: indexPathBeingEdited!) as? NotificationCenterTableViewCell { 
        previousEditedCell.closeEditActions() 
        indexPathBeingEdited = nil 
        //Update the title of Read button 
        previousEditedCell.readUnreadButtonLabel.text = "Read" 
       } 
      } 
     } 
    } 
} 

ビューセル:

func handleLeftSwipe(_ gestureRecognizer: UISwipeGestureRecognizer) { 
    if !isBeingEdited { 
     //Action to open the edit buttons 
     UIView.animate(withDuration: 0.5, animations: { 
      self.notificationHolderViewLeadingConstraint.constant -= 248 
      self.notificationHolderViewTrailingConstraint.constant -= 248 

      self.editActionsView.isHidden = false 
      self.layoutIfNeeded() 
     }, completion: { (success) in 

     }) 
     isBeingEdited = true 
    } 
} 

func closeEditActions() { 
    if isBeingEdited { 
     //Action to open the edit buttons 
     UIView.animate(withDuration: 0.5, animations: { 
      self.notificationHolderViewLeadingConstraint.constant += 248 
      self.notificationHolderViewTrailingConstraint.constant += 248 

      self.editActionsView.isHidden = true 
      self.layoutIfNeeded() 
     }, completion: { (success) in 

     }) 
     isBeingEdited = false 
    } 
} 


override func draw(_ rect: CGRect) { 
    if let viewToRound = editActionsView { 
     let path = UIBezierPath(roundedRect:viewToRound.bounds, 
           byRoundingCorners:[.topRight, .topLeft, .bottomRight, .bottomLeft], 
           cornerRadii: CGSize(width: 20, height: 20)) 

     let maskLayer = CAShapeLayer() 

     maskLayer.path = path.cgPath 
     viewToRound.layer.mask = maskLayer 
    } 
}  

私は自分の編集ボタンを持っています。編集/削除をeditActionsViewに追加しました。対応するアクションは、私のtableViewCellクラスのIBActionsに接続されています。

Final look

関連する問題