Ios 点击UIButton时如何显示搜索栏
我想在一个普通的VC中添加一个搜索栏,当你在那个视图中点击一个按钮时Ios 点击UIButton时如何显示搜索栏,ios,objective-c,uisearchbar,Ios,Objective C,Uisearchbar,我想在一个普通的VC中添加一个搜索栏,当你在那个视图中点击一个按钮时 有没有一种简单/优雅的方法?我认为我必须以编程方式创建动画,但我不知道有什么好的解决方案可以将动画添加到过渡中,而不是仅仅显示和隐藏它们。尝试以下以编程方式创建动画:- UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 70, 320, 44)]; //Now add in your view once you
有没有一种简单/优雅的方法?我认为我必须以编程方式创建动画,但我不知道有什么好的解决方案可以将动画添加到过渡中,而不是仅仅显示和隐藏它们。尝试以下以编程方式创建动画:-
UISearchBar *searchBar = [[UISearchBar alloc]
initWithFrame:CGRectMake(0, 70, 320, 44)];
//Now add in your view once you click on
button
[self.view addSubView:searchBar];
尝试以下方法以编程方式创建:-
UISearchBar *searchBar = [[UISearchBar alloc]
initWithFrame:CGRectMake(0, 70, 320, 44)];
//Now add in your view once you click on
button
[self.view addSubView:searchBar];
首先在ViewController.h中声明对象
@interface ViewController ()
{
UISearchBar *searchBar;
}
@end
而不是在ViewController的viewDidLoad中设置帧。m:
searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0, 320, 44)];
searchBar.hidden=YES;
现在在按钮上添加动画:
- (IBAction)btnEvent:(id)sender
{
searchBar.hidden=NO;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:0.25 animations:^{
searchBar.frame = CGRectMake(0, 20, 320, 44);
[self.view addSubview:searchBar];
}];
}
首先在ViewController.h中声明对象
@interface ViewController ()
{
UISearchBar *searchBar;
}
@end
而不是在ViewController的viewDidLoad中设置帧。m:
searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0, 320, 44)];
searchBar.hidden=YES;
现在在按钮上添加动画:
- (IBAction)btnEvent:(id)sender
{
searchBar.hidden=NO;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:0.25 animations:^{
searchBar.frame = CGRectMake(0, 20, 320, 44);
[self.view addSubview:searchBar];
}];
}