gpt4 book ai didi

ios - 我可以通过 UISearchController 以编程方式复制 UIStatusBar 上的点击吗?

转载 作者:行者123 更新时间:2023-11-29 11:35:34 25 4
gpt4 key购买 nike

UINavigationItem 包含UISearchController。在那种情况下, ScrollView 滚动到顶部包括显示搜索栏。如果我尝试对通常的嫌疑人(调用滚动、设置内容偏移量等)执行此操作,我似乎无法使搜索栏出现。

我能否以编程方式复制点击 UIStatusBar 的功能?

最佳答案

在我看来,我认为Apple在这里使用私有(private)API来制作它。但是如果你想复制一些看起来像它的东西,让搜索栏出现。您可以按照以下步骤操作:

  • UIScrollView 滚动到顶部

    self.scrollView.contentOffset = CGPointZero;
  • 之后,显示搜索栏和大标题

    // Show large title
    self.navigationItem.hidesSearchBarWhenScrolling = NO;
    // Show search bar
    self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways;
  • 当显示搜索栏和大标题时,重置 navigationItem 属性以提供 scrollView 正常行为

    self.navigationItem.hidesSearchBarWhenScrolling = YES;
    self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic;

结果:

enter link description here

工作代码:

[UIView animateWithDuration:0.25f animations:^{
self.scrollView.contentOffset = CGPointZero;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.25f animations:^{
self.navigationItem.hidesSearchBarWhenScrolling = NO;
self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways;
} completion:^(BOOL finished) {
self.navigationItem.hidesSearchBarWhenScrolling = YES;
self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAutomatic;
}];
}];

更详细的可以看my demo repo .

关于ios - 我可以通过 UISearchController 以编程方式复制 UIStatusBar 上的点击吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49597932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com