我正在尝试复制在移动版 Safari 中看到的 UISearchBar 动画。 UISearchBar 不是只移动左边距,而是展开屏幕,然后“跳”到正确的位置。裁员同样不均衡。我怎样才能使这个动画甚至像移动 safari 中的 UISearchBar 一样?
searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0,0,175,44)] autorelease];
searchBar.delegate = self;
searchBar.showsCancelButton = YES;
searchBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;
UIBarButtonItem *customBarItemRight = [[[UIBarButtonItem alloc] initWithCustomView:searchBar] autorelease];
tabBarController.navigationItem.rightBarButtonItem = customBarItemRight;
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
searchDisplayController.searchResultsTableView.hidden = NO;
[UIView animateWithDuration:.3
animations:^ {
CGRect newBounds = searchBar.bounds;
newBounds.size.width = 350;
searchBar.bounds = newBounds;
}];
[searchDisplayController setActive:YES animated:YES];
}
最佳答案
你不应该为此使用 UISearchDisplayController,你需要为你的自定义 View Controller 实现动画。
关于objective-c - 如何使用 block 动画使 UINavigationBar 中的 UISearchBar 仅调整左边距的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4867193/