[英]Call leadingSwipeActionsConfigurationForRowAt from another function
一個不尋常的問題,我有一個 UITableViewCell 有前導和尾隨滑動動作,
有沒有辦法從另一個調用一個?
例如,用戶滑動單元格並出現前導動作,單擊它時,將出現尾隨動作。
當用戶滑動時,單元格的前緣會出現一個圖標,一旦點擊,就會出現尾部動作,並帶有一個刪除單元格的確認按鈕。
這有可能實現嗎?
這是我的代碼:
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let leadingAction = UIContextualAction(style: .normal, title: "", handler: { (leadingAction, view, completionHandler) in
// Action here
completionHandler(true)
})
if let deleteImage = UIImage(named: "Delete")?.cgImage {
leadingAction.image = ImageWithoutRender(cgImage: deleteImage, scale: UIScreen.main.nativeScale, orientation: .up)
}
let preventFullSwipe = UISwipeActionsConfiguration(actions: [leadingAction])
preventFullSwipe.performsFirstActionWithFullSwipe = false
leadingAction.backgroundColor = Colors.clearAlpha
let configuration = UISwipeActionsConfiguration(actions: [leadingAction])
return configuration
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let trailingAction = UIContextualAction(style: .normal, title: "", handler: { (trailingAction, view, completionHandler) in
// Action here
completionHandler(true)
})
if let deleteImage = UIImage(named: "ComfirmDelete")?.cgImage {
trailingAction.image = ImageWithoutRender(cgImage: deleteImage, scale: UIScreen.main.nativeScale, orientation: .up)
}
trailingAction.backgroundColor = Colors.clearAlpha
let configuration = UISwipeActionsConfiguration(actions: [trailingAction])
return configuration
}
您可以通過在尾隨動作完成塊中添加以下行來模擬滑動手勢
let gesture = UIPanGestureRecognizer()
gesture.setTranslation(CGPointMake(0, 100), inView: youtableViewCell)
wasDragged(gesture)
進一步的行為。
func wasDragged (gesture: UIPanGestureRecognizer) {
let translation = gesture.translationInView(youtableViewCell)
let cell = gesture.view!
// Move the object depending on the drag position
cellcontentView.center = CGPoint(x: self.view.bounds.width / 2 + translation.x,
y: self.view.bounds.height / 2 + translation.y)
}
注意:它可能不是一個完美的解決方案,但你可以讓它工作你現在有一個指南:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.