UISearchBar动画隐藏按钮 [英] UISearchBar animation hiding button

查看:84
本文介绍了UISearchBar动画隐藏按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个UISearchBar(附加到UISearchDisplayController),但是我减小了搜索栏的宽度,因此当未选择搜索栏时,可以在其右侧显示一个自定义按钮。该按钮用于访问其他视图。

I currently have a UISearchBar (attached to a UISearchDisplayController), but I reduced the width of the search bar so I could display a custom button to its right when the search bar is not selected. The button is used to access other views.

但是,当我选择搜索栏然后按取消(甚至执行搜索)并返回到普通视图时,在其中应该使用我的自定义按钮显示搜索栏的地方,搜索栏会设置动画并占据按钮的所有空间,并且不会显示。本质上,当我只希望它占据屏幕的一部分时,搜索栏会占据整个屏幕的宽度。

However, when I select the search bar and then press cancel (or even perform a search) and return to the normal view, where the search bar should be displayed with my custom button, the search bar animates and takes up all the room for the button and the is not displayed. Essentially, the search bar takes up all the width of the screen when I only want it to take up a part of it.

有什么方法可以防止搜索栏从动画到屏幕的整个宽度?

Is there any way to prevent the search bar from animating to the whole width of the screen?

这就是我定义搜索栏的CGRect的方式:

This is how I defined the CGRect of the search bar:

self = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 250.0f, 45.0f)]


推荐答案

最后,答案比我想象的要简单。由于某些原因,iPhone SDK会填满搜索栏框架的宽度,因此每次用户按下取消按钮并触发searchBarCancelButtonClicked()事件时,我都必须将其不断重置为所需的大小。一个简单的[searchBar setFrame:frame]解决了它。 :)

In the end, the answer to this was simpler than I thought. For some reason the iPhone SDK fills up the width of the frame of the search bar, so I have to constantly reset it to the size I want every time the user presses the cancel button and the searchBarCancelButtonClicked() event is triggered. A simple [searchBar setFrame: frame] solved it. :)

彼得,您链接的帖子中的问题稍有不同,我已经能够将搜索栏的大小调整为所需的大小,我需要的是阻止它回到全宽。不过感谢您的链接。

Peter, the problem in the post you linked was slightly different, I had already been able to resize the search bar to what I wanted, what I needed was to stop it going back to full width. Thanks for the link though.

这篇关于UISearchBar动画隐藏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆