搜索栏文本确实更改时隐藏特定的视图
作为新手,我终于得到了一个实习案例项目。在直接跳入代码之前,我想询问逻辑。
您可以看到,我在顶部有一个搜索栏,在该页面视图和该集合视图下。因此,我将在PageView中显示到第3个数据,其余的将显示在CollectionView中。每当用户开始在搜索栏中输入时,pageview必须消失,并且CollectionView必须一直延伸到顶部。 (在搜索栏下)和CollectionView必须显示过滤的数据。一旦用户从搜索栏中删除所有文本后,所有内容都应该像开始时一样,并且pageView必须在用户在搜索栏中键入搜索栏之前的同一页面中。 (如果是在2。页面中,则必须在2.页面再次显示后的第2页中)
问题是在使用搜索栏时隐藏pageview。我的想法是编程创建UI,并且一旦搜索栏的textDidchange func运行,隐藏pageview和更改CollectionView的约束。一旦文本为零,请再次可见页面浏览量,然后再次更改约束。
这个逻辑有用吗?有什么更好的方法吗?
As newbie, I finally got a case project for internship. Before jump in directly to code, I would like to ask about a logic.
As you can as see, I have a search bar in the top, and under that a page view and under that a collectionview. So I will display to first 3 data in pageview and rest of it will be displayed in collectionView. Whenever user start typing in searchbar, PageView must disappear and collectionview must go all the way to the top. (under searchbar) And collectionview must display the filtered data. Once user delete all text from search bar, everything should be like in the beginning and pageview must be in the same page before user typed in searchbar. (If it was in the 2. page, it must be in the 2.page after its displayed again)
Problem is with hiding pageview when searchbar is used. My idea is the create ui programmaticly and once textDidChange func of searchBar runs, hide pageView and change constraints of collectionview programmatically. Once text is nil, make pageview visible again and change constraints again.
Is this logic useful? Is there any better way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的方法对我来说似乎是正确的,这也是我的做法。
要添加额外的触摸,您还可以使布局约束更改动画(通过在动画块中调用
layoutifneed
,在Stackoverflow上查找“动画约束”)。为了获得完美的用户体验,请使用
uiviewPropertyanimator
使这些动画可逆,以便如果用户键入字母,然后在动画期间迅速删除它,它将在中间倒转。这是一种有点先进的技术,但是您将通过实施动画获得丰富的经验。观看带有uikit的高级动画来自wwdc17的uikit 以获取更多详细信息。Your approach seems correct to me, that's how I'd do it as well.
To add an extra touch, you can also animate the layout constraints changes (by calling
layoutIfNeeded
in the animation block, look up "animate constraints" on StackOverflow).And for a perfect user experience, make those animations reversible by using
UIViewPropertyAnimator
so that if the user typed a letter and then quickly erased it during the animation it would just reverse in the middle. It's a somewhat advanced technique but you'll gain a great deal of experience with animations by implementing it. Watch Advanced Animations with UIKit from WWDC17 for more details.