UISearchBar自动调整大小并更改帧

 fade2010_480 发布于 2023-02-06 07:47

我有一个搜索栏的问题,当它变成a firstResponder并且它何时退出时,它会以一种奇怪的方式运行.

搜索栏将添加为表视图的标题

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 44.0f)];
self.searchBar.translucent = NO;
self.searchBar.barTintColor = [UIColor grayColor];
self.tableView.tableHeaderView = self.searchBar;

self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar
                                                          contentsController:self];
self.searchController.searchResultsDataSource = self;

视图控制器设置为左侧面板,JASidePanelController当键盘显示或隐藏时,它会隐藏中央面板:

- (void)keyboardWillAppear:(NSNotification *)note
{
    [self.sidePanelController setCenterPanelHidden:YES
                                          animated:YES
                                          duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
    self.searchBar.showsCancelButton = YES;
}

- (void)keyboardWillDisappear:(NSNotification *)note
{
    [self.sidePanelController setCenterPanelHidden:NO
                                          animated:YES
                                          duration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
    self.searchBar.showsCancelButton = NO;
}

正常状态 正常状态

当搜索栏变为a时,firstResponder它会向上移动一个点或随机向下移动

点了 指向下方



当搜索栏退出时,它会动画到达窗口原点,然后返回其自然帧

伸展

到达原点

这是一个重现错误的示例项目.

编辑:

根据@kwylez的 建议,可以通过以下方式避免搜索栏在重新签名时产生的不需要的动画:

self.searchBar.clipsToBounds = YES;

小智.. 8

我通过创建一个ClipBounds设置为YES的UIView解决了这个问题,然后在其中添加了子视图搜索栏.然后将其包含在tableview标题中.它现在正在工作.

谢谢

1 个回答
  • 我通过创建一个ClipBounds设置为YES的UIView解决了这个问题,然后在其中添加了子视图搜索栏.然后将其包含在tableview标题中.它现在正在工作.

    谢谢

    2023-02-06 08:03 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有