Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
756 views
in Technique[技术] by (71.8m points)

background - Swift UIMenu visual glitch when opening submenu

I am setting up context menus with UIMenu and UIAction. When pressing "Delete" I am showing a submenu with "confirm" and "cancel" functions. Everything works fine except one visual glitch that appears 70% of the time. The background of the context menu increases for 1 frame when clicking on "Delete". Every other action works fine. What could this be? Below are screenshots of the process and glitch

Before tapping "Delete" ; Glitch 1 frame after tap ; Afterwards everything is fine

Here is the code I am using to generate the context menu. I am also using a bunch of other table view functions, so you can check out the whole file here: source code Lines 684-805 are the table view code.

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])
    }
}
question from:https://stackoverflow.com/questions/65650034/swift-uimenu-visual-glitch-when-opening-submenu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...