正如我的标题所说,我想从第一行UITableView
左侧滑动到右侧,当用户来到那个ViewController
时。轻扫UITableViewCell无触摸
在我的ViewController
我有一个UITableView
,每行有两个按钮“More”和“Delete”动作。看下面的代码
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
}
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteButton = UITableViewRowAction(style: .normal, title: "Delete") { action, index in
// Edit Button Action
}
deleteButton.backgroundColor = UIColor.red
let editButton = UITableViewRowAction(style: .normal, title: "Edit") { action, index in
// Delete Button Action
}
editButton.backgroundColor = UIColor.lightGray
return [deleteButton, editButton]
}
所有的工作都很好。但我希望当最终用户第一次登录此ViewController
时,他们会通知有可用的滑动操作,以便他们执行此操作。
问题是:我怎样才能左右自动刷第一行?
我做了什么?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let cell = posTblView.cellForRow(at: NSIndexPath(row: 0, section: 0) as IndexPath) as! POSUserTabelCell
UIView.animate(withDuration: 0.3, animations: {
cell.transform = CGAffineTransform.identity.translatedBy(x: -150, y: 0)
}) { (finished) in
UIView.animateKeyframes(withDuration: 0.3, delay: 0.25, options: [], animations: {
cell.transform = CGAffineTransform.identity
}, completion: { (finished) in
})
}
}
通过上面的代码刷卡/移动单元格正在工作,但不显示“删除”和“更多”按钮。
所以请引导我正确的方向。
您的方法似乎适合左右滑动。但是,我不确定内置按钮是否可以像这样突出显示。你可以肯定的做法是在你的内容下面放置一个看起来像本地控件的UIView,做一些滑动操作来展示它们,并且将它们从单元格中移除/隐藏。看看这个答案:https://stackoverflow.com/questions/5301728/is-it-possible-to-programmatically-show-the-red-delete-button-on-a-uitableviewce – dirtydanee
你可以使用这个旧的框架: https://github.com/CEWendel/SWTableViewCell。然后在viewdidappear写: [cell showRightUtilityButtonsAnimated:YES]; –
那么,你的目标是让第一行自动滑动,这样你就可以看到编辑按钮。是对的吗? –