我有一个带有阴影和上下文菜单的矩形。当我关闭这个上下文菜单时,矩形的阴影会延迟出现(~0.5秒)。完整矩形的阴影以及内部元素的阴影。我不知道我做错了什么
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
if collectionView == foodOnTheShelf {
let config = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { _ in
let edit = UIAction(title: "Изменить", image: UIImage(systemName: "pencil"), identifier: nil, discoverabilityTitle: nil, state: .off) { _ in
self.alert.showAlert(viewController: self,
image: UIImage(named: test[indexPath.row].name)!,
food: test[indexPath.row],
picker: self.picker,
consumePicker: self.consumePicker,
unit: self.unit,
currentWeigt: test[indexPath.row].weight,
currentProductDate: test[indexPath.row].productionDate,
currentExperationDate: test[indexPath.row].expirationDate,
searchController: nil)
}
let delete = UIAction(title: "Удалить", image: UIImage(systemName: "trash"), attributes: .destructive) { _ in
test.remove(at: indexPath.row)
self.viewDidAppear(true)
}
return UIMenu(title: "", image: nil, identifier: nil, options: UIMenu.Options.displayInline , children: [edit, delete])
}
return config
}
return nil
}发布于 2022-09-21 05:41:48
基于这个答案,您可以向盘过渡视图添加阴影,这是在上下文菜单中断结束后显示的临时视图。
问题是这个转换视图是一个私有类(_UIContextMenuPlatterTransitionView),所以如果使用它,应用程序将被拒绝。
func collectionView(_ collectionView: UICollectionView, willEndContextMenuInteraction configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
guard let platter = platterTransitionView() else { return }
addShadow(to: platter.layer) // add a shadow the same way you do for your cells
}
private func platterTransitionView() -> UIView? {
guard let container = self.view.window?.subviews.filter({ type(of: $0) == NSClassFromString("_UIContextMenuContainerView") }).first else { return nil }
return container.subviews.filter({ type(of: $0) == NSClassFromString("_UIContextMenuPlatterTransitionView") }).first
}您也可以尝试在不检查其类的情况下访问转换视图,但这种方式并不安全/动态:
let platter = self.view.window?.subviews[2].subviews[1]https://stackoverflow.com/questions/73112474
复制相似问题