UIContextMenuInteraction выдает предупреждения NSLayoutConstraint при взаимодействии и смещении tableView ниже
У меня есть UITableView
для отображения серии данных в разных ячейках. Я добавилUIContextMenuInteraction
к tableView
так что я могу взаимодействовать с каждой ячейкой и получить предварительный просмотр. Когда я выполняю взаимодействие с любой ячейкой, она сначала выдает кучу предупреждений об ограничениях. В предупреждениях упоминается оgroupView
на который я никогда не ссылаюсь и не обращаюсь к нему, если только это не содержимое контекстного меню по умолчанию.
Также при выходе из взаимодействия tableView ведет себя странно, сдвигая tableView вниз, прежде чем вернуться в нормальное состояние - см. Здесь: https://streamable.com/3g5byj
Код:
extension ProjectsViewController: UIContextMenuInteractionDelegate {
private func setupContextMenuInteraction() {
let interaction = UIContextMenuInteraction(delegate: self)
tableView.addInteraction(interaction)
}
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
guard let indexPath = tableView.indexPathForRow(at: location), let _ = tableView.cellForRow(at: indexPath) else { return nil }
let project = projects[indexPath.section]
return UIContextMenuConfiguration(identifier: "\(indexPath.section)" as NSCopying, previewProvider: {
let projectViewController = ProjectViewController(project: project)
return projectViewController
}) { actions -> UIMenu? in
let favourite = UIAction(title: "Favourite", image: UIImage(systemName: "star"), identifier: nil) { _ in
}
let share = UIAction(title: "Share", image: UIImage(systemName: "square.and.arrow.up"), identifier: nil) { _ in
guard let url = URL(string: project.url) else { return }
let activityController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
DispatchQueue.main.async {
self.present(activityController, animated: true, completion: nil)
}
}
return UIMenu(title: "", children: [favourite, share])
}
}
}
Предупреждение об ограничениях:
2020-05-16 19:56:40.398521+0200 MyApp[2690:219904] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x600002b75180 h=--& v=--& UIInterfaceActionGroupView:0x7fc782c500f0.height == 0 (active)>",
"<NSLayoutConstraint:0x600002b79950 groupView.actionsSequence....height >= 66 (active, names: groupView.actionsSequence...:0x7fc78311c800 )>",
"<NSLayoutConstraint:0x600002b794f0 UIInterfaceActionGroupView:0x7fc782c500f0.top == _UIContentConstraintsLayoutGuide:0x7fc782c4eb30''.top (active)>",
"<NSLayoutConstraint:0x600002b79540 V:[_UIContentConstraintsLayoutGuide:0x7fc782c4eb30'']-(0)-| (active, names: '|':UIInterfaceActionGroupView:0x7fc782c500f0 )>",
"<NSLayoutConstraint:0x600002b79f40 groupView.actionsSequence....top == _UIContentConstraintsLayoutGuide:0x7fc782c4eb30''.top (active, names: groupView.actionsSequence...:0x7fc78311c800 )>",
"<NSLayoutConstraint:0x600002b79f90 groupView.actionsSequence....bottom == _UIContentConstraintsLayoutGuide:0x7fc782c4eb30''.bottom (active, names: groupView.actionsSequence...:0x7fc78311c800 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600002b79950 groupView.actionsSequence....height >= 66 (active, names: groupView.actionsSequence...:0x7fc78311c800 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.