英文:
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:
- Why can I see this in the navigation? (I don't add this)
- 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.")
Questions:
- Why can I see this in the navigation? (I don't add this)
- 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;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论