Reputation: 661
I am displaying menu from button as follow:
final class YourCustomCollectionViewCell: UICollectionViewCell {
private let menuButton: UIButton = {
let button = UIButton()
button.showsMenuAsPrimaryAction = true
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
override class func awakeFromNib() {
super.awakeFromNib()
self.contentView.addSubview(menuButton)
configureButtonConstraints()
configureMenu()
}
private func configureButtonConstraints() {
NSLayoutConstraint.activate([
menuButton.topAnchor.constraint(equalTo: self.topAnchor),
menuButton.leadingAnchor.constraint(equalTo: self.leadingAnchor),
menuButton.trailingAnchor.constraint(equalTo: self.trailingAnchor),
menuButton.bottomAnchor.constraint(equalTo: self.bottomAnchor)
])
}
private func configureMenu() {
let editAction = UIAction(title: "Edit") { _ in
print("Edit Button Clicked")
}
let deleteAction = UIAction(title: "Delete") { _ in
print("Delete Button Clicked")
}
let menuForCell = UIMenu(title: "Options", options: UIMenu.Options.displayInline, children: [editAction, deleteAction])
menuButton.menu = menuForCell
}
}
It works fine to display menu, but after display of 1 second menu is moved to the top of screen and not showing beside the button.
How can I solve this?
Thank you,
Upvotes: 1
Views: 51