添加到UISearchDisplayController时,UISearchBar在状态栏下剪切 [英] UISearchBar clipped under status bar when added to UISearchDisplayController

查看:111
本文介绍了添加到UISearchDisplayController时,UISearchBar在状态栏下剪切的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的搜索栏将其背景向上扩展到状态栏下方,如下所示:

I want my search bar to draw its background extended upwards below the status bar like this:

这是上图中的相应代码:

This is the corresponding code for the image above:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.searchBar = [[UISearchBar alloc] init];
    self.searchBar.delegate = self;
    [self.view addSubview:self.searchBar];

    self.searchBar.translatesAutoresizingMaskIntoConstraints = NO;
    NSDictionary *views = @{@"v":self.searchBar,
                            @"topLayoutGuide":self.topLayoutGuide};

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide][v]" options:0 metrics:nil views:views]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]|" options:0 metrics:nil views:views]];

    [self.searchBar setBackgroundImage:[UIImage imageNamed:@"searchbarBG"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
}

- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar
{
    return UIBarPositionTopAttached;
}

当我将搜索栏添加到<$时出现问题c $ c> UISearchDisplayController 通过在 viewDidLoad 方法的末尾附加以下行:

The problem arises when I add the search bar to a UISearchDisplayController by appending the following line at the end of the viewDidLoad method:

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

这是我得到的结果:

请注意图像看起来很紧张。这与我在代码中将UIBarPositionTopAttached更改为UIBarPositionTop的情况不同:

Note that the image looks clipped. This is different from what it looks like if I change UIBarPositionTopAttached to UIBarPositionTop in the code:

被剪裁的图像让我想到 clipsToBounds 我可以通过在 viewDidLoad 的末尾添加这段代码来正确显示搜索栏:

The image being clipped made me think of clipsToBounds and I could get the search bar to display properly by adding this piece of code at the end of viewDidLoad:

for (UIView *subview in self.searchBar.subviews) {
    subview.clipsToBounds = NO;
}

所以我想 UISearchDisplayController 正在搞乱 UISearchBar 背景视图的 clipsToBounds 属性。还有其他人在努力吗?我的代码有问题吗?

So I guess the UISearchDisplayController is messing with the clipsToBounds property of the UISearchBar background view. Has anyone else struggled with this? Is there a problem with my code?

2013年10月,除了发布此问题外,我还使用Apple Bug Reporter工具报告了这一点。 2015年1月6日(waaaay为时已晚)我收到了Apple Developer Relations的回复:

Back in October 2013, besides posting this question, I also reported this using the Apple Bug Reporter tool. On January 6, 2015 (waaaay too late) I got a reply from Apple Developer Relations:


没有计划根据这个来解决这个问题以下内容:

There are no plans to address this based on the following:

不再支持UISearchDisplayController。 UISearchController应该提供所需的
功能,如果不是
(或行为不正确),请提交新的bug。

UISearchDisplayController is no longer supported. The desired functionality should be available with UISearchController and if not (or is behaving incorrectly), please file a new bug.

我们现在关闭此报告。

如果您对解决方案有疑问,或者这对您来说仍然是一个
关键问题,请用此更新您的错误报告
信息。

If you have questions about the resolution, or if this is still a critical issue for you, then please update your bug report with that information.

请确保定期检查新的Apple版本是否有任何可能影响此问题的更新

Please be sure to regularly check new Apple releases for any updates that might affect this issue.


推荐答案

我遇到了完全相同的问题,但强迫searchBar的clipsToBounds为YES。无需自动布局或UIBarPositioning协议方法。

I was having the exact same issue, but forcing clipsToBounds to YES for the searchBar, did the trick. No need of auto-layout nor UIBarPositioning protocol methods.

这篇关于添加到UISearchDisplayController时,UISearchBar在状态栏下剪切的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆