objective-c - 如何使用 block 动画使 UINavigationBar 中的 UISearchBar 仅调整左边距的大小?

标签 objective-c ios animation uisearchbar

我正在尝试复制在移动版 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/

相关文章:

ios - 如何在 iOS 的 openfire/xmpp 中获取所有在线用户的列表?

iphone - 停止位置 :fixed from zooming with user in iOS?

iOS 键盘使 View 消失

ios - 在点击按钮时动画滚动到 tableview 的底部?

ios - 如何释放在方法中创建的字符串?

java - 如何在没有 Opengl ES 的情况下为对象制作动画?

ios - 除了 swift 中的按钮操作外,UIView 没有显示

ios - 从子类到父类的自定义委托(delegate)(subview-superview)

ios - 使用 CoreMotion 在后台获取加速度计数据

jquery - 如何延迟 animate.css 中的无限类?