vie*_*n09 5 animation objective-c uisearchbar ios
我使用此代码将视频栏添加到视图控制器中.
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 64, MAINSCREEN.size.width, self.searchBar.frame.size.height)];
self.searchBar.delegate = self;
self.searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
self.searchDisplayController.delegate = self;
self.searchDisplayController.searchResultsDataSource = self;
[self.view addSubview:self.searchBar];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64 + self.searchBar.frame.size.height, MAINSCREEN.size.width, MAINSCREEN.size.height)];
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
Run Code Online (Sandbox Code Playgroud)
我必须以编程方式将搜索栏和表格视图添加到视图中,因为我希望搜索栏始终位于表格视图的顶部,因此我使用了这些代码.
不幸的是,有一个问题,当我修复位置时搜索栏没有动画,CGRectMake所以我必须创建自己的动画来处理这个代码的问题.
- (BOOL)searchBarShouldBeginEditing:(UISearchBar*)searchBar {
[UIView animateWithDuration:0.55f
delay:0
usingSpringWithDamping:500.0f
initialSpringVelocity:0
options:UIViewAnimationOptionOverrideInheritedDuration
animations:^{
self.searchBar.frame = CGRectMake(0, 20, MAINSCREEN.size.width, self.searchBar.frame.size.height);
}
completion:nil];
return YES;
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
[UIView animateWithDuration:0.6f
delay:0
usingSpringWithDamping:500.0f
initialSpringVelocity:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
self.searchBar.frame = CGRectMake(0, 64, MAINSCREEN.size.width, self.searchBar.frame.size.height);
}
completion:nil];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
但是当阴影和物体有太多不同时,它的运动看起来有点愚蠢,我已经拍摄了一个gif图像,目前是慢动作.
那么如何以正确的方式调整搜索栏的动画,使其与阴影和导航栏一起运行相同?
感谢帮助.