UINavigationItem显示菜单按钮的原因是什么?

huangapple go评论60阅读模式
英文:

Why UINavigationItem shows menu button?

问题

I have UINavigationItem with UISearachController;

#warning - addded UISearchController
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
if (@available(iOS 16.0, *)) {
self.navigationItem.preferredSearchBarPlacement = UINavigationItemSearchBarPlacementInline;

}
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.definesPresentationContext = YES;
self.searchController.obscuresBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.placeholder = @"Search";
self.searchController.searchBar.searchBarStyle = UISearchBarStyleProminent;
[self.searchController.searchBar sizeToFit];

When I tap on the search button in the navigation bar then I can see a search field and some button with three dots(it looks like UIContextMenu, and after tapping on this button in log, I see "[UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:] while no context menu is visible. This won't do anything.")

Questions:

  1. Why can I see this in the navigation? (I don't add this)
  2. how can I remove this button from the navigation view
英文:

I have UINavigationItem with UISearachController;

#warning - addded UISearchController
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
if (@available(iOS 16.0, *)) {
    self.navigationItem.preferredSearchBarPlacement = UINavigationItemSearchBarPlacementInline;
    
}
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.definesPresentationContext = YES;
self.searchController.obscuresBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.placeholder = @"Search";
self.searchController.searchBar.searchBarStyle = UISearchBarStyleProminent;
[self.searchController.searchBar sizeToFit];

When I tap on the search button in the navigation bar then I can see a search field and some button with three dots(it looks like UIContextMenu, and after tapping on this button in log, I see "[UILog] Called -[UIContextMenuInteraction updateVisibleMenuWithBlock:] while no context menu is visible. This won't do anything.")

UINavigationItem显示菜单按钮的原因是什么?

Questions:

  1. Why can I see this in the navigation? (I don't add this)
  2. how can I remove this button from the navigation view

答案1

得分: 0

这可能是因为导航栏将所有额外的按钮包装在上下文菜单中而发生的。这是在WWDC 2022中引入的新功能。您可以查看此视频以获取更多详细信息:https://developer.apple.com/videos/play/wwdc2022/10069/

英文:

It could be happening because of navigation bar wrapping all the extra buttons in a context menu. This was a new feature introduced in WWDC 2022. You can check out this video for more details: https://developer.apple.com/videos/play/wwdc2022/10069/

答案2

得分: 0

所以这个元素被命名为“Overflow support button”。 (感谢@Mozz)

如果您将任何项目添加到navigationItem.rightBarButtonItems中,然后在打开搜索栏时可以看到这个“Overflow button” (self.navigationItem.preferredSearchBarPlacement = UINavigationItemSearchBarPlacementInline;)

在我的情况下,我已重新实现了rightBarButtonItem,这使我可以省略“Overflow button”的表示

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:self.modeButton];
if (@available(iOS 16.0, *)) {
    UIBarButtonItemGroup *group = [[UIBarButtonItemGroup alloc] init];
    group.alwaysAvailable = YES;
    group.representativeItem = barButton;
    self.navigationItem.pinnedTrailingGroup = group;
} else {
    self.navigationItem.rightBarButtonItem = barButton;
}
英文:

so this element is named "Overflow support button". (thanks @Mozz)

If you add any item to navigationItem.rightBarButtonItems then you can see this "Overflow button" when open searchbar (self.navigationItem.preferredSearchBarPlacement = UINavigationItemSearchBarPlacementInline;)

In my case I have reimplemented rightBarButtonItem and this allows me to omit the representation of "Overflow button"

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:self.modeButton];
if (@available(iOS 16.0, *)) {
    UIBarButtonItemGroup *group = [[UIBarButtonItemGroup alloc] init];
    group.alwaysAvailable = YES;
    group.representativeItem = barButton;
    self.navigationItem.pinnedTrailingGroup = group;
} else {
    self.navigationItem.rightBarButtonItem = barButton;
}

huangapple
  • 本文由 发表于 2023年5月25日 02:03:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定