如何解决打开子菜单时 Swift UIMenu 视觉故障
我正在使用 UIMenu 和 UIAction 设置上下文菜单。当按下“删除”时,我会显示一个带有“确认”和“取消”功能的子菜单。除了出现 70% 的视觉故障外,一切正常。单击“删除”时,上下文菜单的背景会增加 1 帧。所有其他操作都可以正常工作。这可能是什么?以下是过程和故障的截图
Before tapping "Delete" ; Glitch 1 frame after tap; Afterwards everything is fine
这是我用来生成上下文菜单的代码。我还使用了许多其他表格视图函数,因此您可以在此处查看整个文件:source code 第 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",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])
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。