简体   繁体   English

如何让iOS 15中的搜索栏默认出现?

[英]How to make search bar in iOS 15 appear by default?

I started to develop an application using iOS15 and the new.searchable modifier.我开始使用 iOS15 和 new.searchable 修饰符开发应用程序。

I have a simple layout with some placeholder results on the main page and a search field attached to the navigationBar.我有一个简单的布局,在主页上有一些占位符结果和一个附加到导航栏的搜索字段。

Currently, if the user loads the page and looks at the results (even scrolls a bit) will not be able find the search field as it's hidden by default.目前,如果用户加载页面并查看结果(甚至滚动一点)将无法找到搜索字段,因为它默认隐藏。 The user needs to scroll in reverse for the search bar to appear.用户需要向后滚动才能显示搜索栏。

How is this a good for UX?这对用户体验有什么好处?

The only workaround is the drawer placement with.always, but that will make the navigation title inline.唯一的解决方法是抽屉放置 with.always,但这会使导航标题内嵌。

I really want to achieve the result from the Notes app, that has the search bar visible all the time.我真的很想从 Notes 应用程序中获得结果,它的搜索栏始终可见。

Any workaround?任何解决方法? Was this feature really tested by anyone in a real app?此功能是否真的由任何人在真实应用程序中测试过?

What I want:我想要的是: 我想要的是

What I get:我得到什么: 我得到什么

You need to set the NavigationBarDrawerDisplayMode for the searchable modifier.您需要为searchable修饰符设置 NavigationBarDrawerDisplayMode。 By default it's set to automatic.默认情况下,它设置为自动。

public struct NavigationBarDrawerDisplayMode {

    /// Allow the search field to be collapsed as the user scrolls
    /// their content.
    public static let automatic: SearchFieldPlacement.NavigationBarDrawerDisplayMode

    /// Always display the search field no matter the scroll position of
    /// the user's content.
    public static let always: SearchFieldPlacement.NavigationBarDrawerDisplayMode
}

The usage would be as follows.用法如下。

.searchable(text: $search, placement: .navigationBarDrawer(displayMode: .always), prompt: "Search")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM