Визуальный сбой Swift UIMenu при открытии подменю
Я настраиваю контекстные меню с помощью UIMenu и UIAction. При нажатии «Удалить» я показываю подменю с функциями «подтвердить» и «отменить». Все работает нормально, кроме одного визуального глюка, который проявляется в 70% случаев. Фон контекстного меню увеличивается на 1 кадр при нажатии на "Удалить". Любое другое действие работает нормально. Что бы это могло быть? Ниже скриншоты процесса и глюка
Прежде чем нажать «Удалить» ; Глюк 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])
}
}