带动画的导航栏中的iOS自定义搜索栏?
我知道关于在导航栏中添加搜索栏的问题在这里被问了很多次(我知道这个过程)。但我的问题是,我必须用自定义背景显示搜索栏,当我单击添加到导航栏右侧的按钮时,它必须显示/隐藏动画。 当前搜索栏之前 最终用户界面(单击搜索图标后)- 任何帮助都将不胜感激 代码是带动画的导航栏中的iOS自定义搜索栏?,ios,objective-c,uinavigationbar,uisearchbar,Ios,Objective C,Uinavigationbar,Uisearchbar,我知道关于在导航栏中添加搜索栏的问题在这里被问了很多次(我知道这个过程)。但我的问题是,我必须用自定义背景显示搜索栏,当我单击添加到导航栏右侧的按钮时,它必须显示/隐藏动画。 当前搜索栏之前 最终用户界面(单击搜索图标后)- 任何帮助都将不胜感激 代码是 //search bar searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(20, 0, self.view.frame.size.width-10-60, 44)]
//search bar
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(20, 0, self.view.frame.size.width-10-60, 44)];
// searchBar.translucent = NO;
//searchBar.barTintColor = [UIColor clearColor];
searchBar.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar addSubview:searchBar];
float delta = searchBar.frame.size.width;
searchBar.frame = CGRectOffset(searchBar.frame, -delta, 0.0);
searchBar.hidden = YES;
-(void)rightbuttonPressed
{
// get the width of the search bar
float delta = searchBar.frame.size.width;
// check if toolbar was visible or hidden before the animation
BOOL isHidden = [searchBar isHidden];
// if search bar was visible set delta to negative value
if (!isHidden) {
delta *= -1;
} else {
// if search bar was hidden then make it visible
searchBar.hidden = NO;
}
// run animation 0.7 second and no delay
[UIView animateWithDuration:0.7 delay: 0.0 options: UIViewAnimationOptionCurveEaseIn animations:^{
// move search bar delta units left or right
searchBar.frame = CGRectOffset(searchBar.frame, delta, 0.0);
} completion:^(BOOL finished) {
//if the bar was visible then hide it
if (!isHidden) {
searchBar.hidden = YES;
}
}];
}
不要将搜索栏添加为导航栏上的子视图。而是将其设置为当前视图控制器的
navigationItem
的标题视图
在UIView中添加搜索栏,并将视图指定给titleView。在该视图中设置搜索栏的动画,与平常一样。对于背景,
UISearchBar
有一个backgroundImage
属性。请共享您添加的codecode-added-plz-check,但如何设置标题视图动画和更多导入如何添加自定义背景图像?