我想在文本上方添加像iMessage这样的反应:

目前,我只能显示菜单,不确定如何在上面添加自定义视图。我的是这样的:

如何添加与iMessage reactions视图相似的视图?
下面是我在收藏视图中创建上下文菜单的方式:
override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let post = isFiltering ? filteredPosts[indexPath.section] : posts[indexPath.section]
let identifier = NSString(string: "\(post.createdAt)")
if post.username == "" {return nil}
return UIContextMenuConfiguration(identifier: identifier, previewProvider: nil) { _ -> UIMenu? in
let deleteAction = UIAction(title: "Delete", image: UIImage(systemName: "trash")) { _ in
Service.deletePost(post: post)
}
let replyAction = UIAction(title: "Reply", image: UIImage(systemName: "arrowshape.turn.up.left")) { _ in
self.setReplyingView(post: post)
}
let noteTagAction = UIAction(title: "Add Note Tag", image: UIImage(named: "noteFilterBlack")) { _ in
DispatchQueue.main.async {
Service.addTag(named: "note", toPostWithId: post.id)
}
}
let examTagAction = UIAction(title: "Add Exam Tag", image: UIImage(named: "examFilterBlack")) { _ in
DispatchQueue.main.async {
Service.addTag(named: "exam", toPostWithId: post.id)
}
}
let assignmentTagAction = UIAction(title: "Add Assignment Tag", image: UIImage(named: "assignmentFilterBlack")) { _ in
DispatchQueue.main.async {
Service.addTag(named: "assignment", toPostWithId: post.id)
}
}
let questionTagAction = UIAction(title: "Add Question Tag", image: UIImage(named: "questionFilterBlack")) { _ in
DispatchQueue.main.async {
Service.addTag(named: "question", toPostWithId: post.id)
}
}
guard let user = Service.shared.getUser() else { return UIMenu(title: "", children: [replyAction, deleteAction])}
if user.uid == post.userId {
return UIMenu(title: "", children: [replyAction, noteTagAction, examTagAction, assignmentTagAction, questionTagAction ,deleteAction])
} else {
return UIMenu(title: "", children: [replyAction, noteTagAction, examTagAction, assignmentTagAction, questionTagAction])
}
}
}但是,在返回UIContextMenuConfiguration时,我看不到添加自定义视图的选项。
发布于 2021-02-15 19:25:31
当您创建UIContextMenuConfiguration时,这里有一个参数,它在这里接受闭包'previewProvider‘,您可以返回您的自定义视图。下面是一个例子..
UIContextMenuConfiguration(identifier: "unique-id", previewProvider: {
let customView = CustomViewController()
return customView
}, actionProvider: {
})https://stackoverflow.com/questions/65924726
复制相似问题