作者:你是幸福的真光 | 来源:互联网 | 2023-01-13 15:35
在我的应用程序中,一个屏幕具有表格视图并在滑动时显示"编辑"和"删除"按钮UITableViewCell
.
一切都运行良好,但问题是UITableViewCell
在iOS 11 中的默认动画.
我知道iOS 11中的某些行为和基础已经改变.当您继续拉动您的单元格时,editActionsForRowAt
将自动调用方法.
有时它很好但是当你在桌子上添加了一个按钮时,然后看起来丑陋的行为.
请看下面,iOS 10和iOS 11中滑动单元格的默认行为.
iOS 10:
![在此输入图像描述](https://img.php1.cn/3cd4a/1eebe/cd5/02c379d60086f382.webp)
iOS 11:
![在此输入图像描述](https://img.php1.cn/3cd4a/1eebe/cd5/a1be7872e8d4934f.webp)
你可以看到iOS 11
我是否拉动然后自动editActionsForRowAt
方法os调用并显示警告信息.
我的问题:有没有什么可以阻止这种iOS 11的行为和代码?
因为如果你的桌子有超过2个按钮,那么它看起来很难看.
1> Micah Wilson..:
这似乎做你想要的.然而,动画与iOS 10中的动画并不完全相同,但它消除了完全滑动,但仍然看起来不错.
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction.init(style: UIContextualAction.Style.destructive, title: "Delete", handler: { (action, view, completion) in
//TODO: Delete
completion(true)
})
let editAction = UIContextualAction.init(style: UIContextualAction.Style.normal, title: "Edit", handler: { (action, view, completion) in
//TODO: Edit
completion(true)
})
let cOnfig= UISwipeActionsConfiguration(actions: [deleteAction, editAction])
config.performsFirstActiOnWithFullSwipe= false
return config
}
关键线是config.performsFirstActiOnWithFullSwipe= false
因为这将禁用完整滑动.
以上代码将func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath)
在iOS 11上覆盖,但您editActionsforRowAt
仍将用于子iOS 10设备.