gpt4 book ai didi

iphone - UISearchBar 不向上移动

转载 作者:可可西里 更新时间:2023-11-01 03:38:23 28 4
gpt4 key购买 nike

我不知道为什么默认动画会失败。

我的搜索栏没有按预期向上移动。

View 在 UIView 中,我想知道是否是这个问题。

包括IB布局

enter image description here enter image description here enter image description here

最佳答案

在“俯卧撑”动画中,搜索栏实际上并没有移动。相反,它会在导航栏上升时保持原位,从而拉动 View 的其余部分。您应该能够通过注册为它的委托(delegate) (UISearchBarDelegate) 并响应这些调用,在代码中手动移动搜索栏。

#pragma mark - UISearchBarDelegate Methods
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
//move the search bar up to the correct location eg
[UIView animateWithDuration:.4
animations:^{
searchBar.frame = CGRectMake(searchBar.frame.origin.x,
0,
searchBar.frame.size.width,
searchBar.frame.size.height);
}
completion:^(BOOL finished){
//whatever else you may need to do
}];
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
//move the search bar down to the correct location eg
[UIView animateWithDuration:.4
animations:^{
searchBar.frame = CGRectMake(searchBar.frame.origin.x,
/*SearchBar original Y*/,
searchBar.frame.size.width,
searchBar.frame.size.height);
}
completion:^(BOOL finished){
//whatever else you may need to do
}];
}

关于iphone - UISearchBar 不向上移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8007883/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com