swift - 打开子菜单时的 Swift UIMenu 视觉故障
问题描述
我正在使用 UIMenu 和 UIAction 设置上下文菜单。当按下“删除”时,我会显示一个带有“确认”和“取消”功能的子菜单。除了 70% 的时间出现的一个视觉故障外,一切正常。单击“删除”时,上下文菜单的背景会增加 1 帧。其他所有操作都可以正常工作。这可能是什么?下面是过程和故障的截图
这是我用来生成上下文菜单的代码。我还使用了许多其他表格视图功能,因此您可以在此处查看整个文件:源代码第 684-805 行是表格视图代码。
func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
if indexPath.row == habits.count { //if its the last cell which is empty
return nil
}
return UIContextMenuConfiguration(identifier: indexPath as NSIndexPath, previewProvider: nil) { suggestedActions in
let removeCancel = UIAction(title: "Cancel", image: UIImage(systemName: "xmark")) { action in }
let removeConfirm = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { action in
self.removeHabit(index: indexPath.row)
}
let remove = UIMenu(title: "Delete", image: UIImage(systemName: "trash"), options: .destructive, children: [removeCancel, removeConfirm])
let edit = UIAction(title: "Edit", image: UIImage(systemName: "square.and.pencil")) { action in
self.openEditHabit(index: indexPath.row)
}
let reset = UIAction(title: "Reset today", image: UIImage(systemName: "arrow.counterclockwise")) { action in
self.resetHabit(index: indexPath.row)
}
let reorder = UIAction(title: "Reorder", image: UIImage(systemName: "arrow.up.arrow.down")) { action in
self.tableView.isEditing = true
UISelectionFeedbackGenerator().selectionChanged()
}
let cheat = UIAction(title: "Fix streak", image: UIImage(systemName: "slider.horizontal.3")) { action in
//
}
var contextMenu = [UIAction]()
if (self.habits[indexPath.row].doneToday) {
contextMenu.append(reset)
}
contextMenu.append(reorder)
contextMenu.append(edit)
let nonDestructive = UIMenu(options: .displayInline, children: contextMenu)
return UIMenu(children: [nonDestructive, remove, cheat])
}
}
解决方案
推荐阅读
- php - 由于服务器负载,php7-fpm strtotime 是否会将此日期“4/10/2019 13:54:21”视为无效输入?
- asp.net-mvc - .Net Core Vs .Net 框架创建一个新的 mvc web 应用程序
- python - Python Producer 可以通过 shell 发送,但不能通过 .py
- sql - Oracle SQL 查询优化(左连接、索引)
- java - 从 URL 将图像加载到视图后如何将图像保存到磁盘
- functional-programming - ImmutableJS vs Ramda 或 ImmutableJS + Ramda - 它们可以一起使用吗
- oculusgo - Oculus Go:如何在应用程序中保持清醒
- jquery - 添加带有输入占位符的标签
- python - 导入同名函数会覆盖吗?
- javascript - React Navigation:组件未在弹出或后退按钮上卸载 #5775