BTNavigationDropdownMenu
BTNavigationDropdownMenu copied to clipboard
Only opening dropdown menu when tapping on center
Dropdown view won't open when I press on the drop down button. It will only work when I tap the center of the text, which isn't where a user would instinctively tap.
I don't notice this behavior, tapping on the arrow works as expected.
Problem in this code:
// Get titleSize
let titleSize = (title as NSString).sizeWithAttributes([NSFontAttributeName:self.configuration.cellTextLabelFont])
// Set frame
let frame = CGRectMake(0, 0, titleSize.width + (self.configuration.arrowPadding + self.configuration.arrowImage.size.width)*2, self.navigationController!.navigationBar.frame.height)
For example, If title is only 5 characters long and second item title is 20 characters long, then taps near bounds of second item will not work. I think you should recalculate frame after changing an item.
The menu Button frame should dynamically update when another menu item is selected. This might be achieved with a delegate method.
maybe a temporary workaround is to set the frame according to the longest title's size, not to the initial nav bar title.
in the initializer I changed the code as shown below. However, now it is possible to tap outside of the shortest title and the menu still opens.... But still better than not being able to tap the arrow beside the longest title.
// Get titleSize // get longest title
var titleLength = CGFloat(0)
var longestTitle = title
for item in items {
let titleWidth = (item.title as NSString).size(attributes: [NSFontAttributeName:self.configuration.navigationBarTitleFont]).width
if titleWidth > titleLength {
titleLength = titleWidth
longestTitle = item.title
print("longest title is \(item.title)")
}
}
let titleSize = (longestTitle as NSString).size(attributes[NSFontAttributeName:self.configuration.navigationBarTitleFont])
here is the complete code: https://github.com/DominikButz/BTNavigationDropdownMenu/tree/ItemImage
This problem still exists Any fix ?