ios - UISearchBar AutoLayout ios7 错误?

标签 ios ios7 autolayout

我正在使用 AutoLayout 并有一个 UISearchBar、UITableView 和一个 UIView。最初布局是正确的,并根据我的 AutoLayout 规则定位。

enter image description here

当 UISearchBar 获得焦点时,它的高度会突然扩大,覆盖我的顶部 UIView。

enter image description here

无论我如何布局我的自动布局约束,这种情况都会发生。

如果我不设置

self.searchBar.translatesAutoresizingMaskIntoConstraints = NO;

并设置一个框架,然后它的行为就正常了。

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 100.0f, 45.0f)];

但我在这个适用于 iOS7 的应用程序中依赖于 AutoLayout。这是一个真正的错误吗?或者很可能我错过了什么!

最佳答案

遇到了同样的问题。在 viewDidLoad 中试试这个

if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
    self.edgesForExtendedLayout = UIRectEdgeNone;
}

关于ios - UISearchBar AutoLayout ios7 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19151415/

相关文章:

iOS 应用程序仅在 iPad Air 上崩溃

ios - iOS 7上的动画问题,但iOS 8上没有

swift - 每行安装 2 个 Collection View 单元格(在所有设备上都相同)

swift - 单个 UIView 和多个 TableView 的自动布局

objective-c - 使用 OpenAL 在 iOS 上进行离线录音

ios - 将带有数字的标签与带有数字的文本字段相乘

ios - 使用 UILocalNotifications、带有完成处理程序的远程通知和后台获取

ios - 无法同时满足约束自定义 header 部分

ios - 如何更改坐标注释的图像?

ios - Swift 通过 UITabBarController 访问 viewController 的函数