Update management using the Display Display Controller is displayed above the search bar.

I implemented a simple table view controller with a search display controller, which I pulled through Interface Builder. Then I turned on the update so that the update control is displayed when the user pauses to update.

The problem is that the spinner is displayed on top of the search bar when it should lie under it.

I know the reason is the minimal search style. If you use the default pop style, the problem does not exist.

When you slowly pull down, you will see that the first line appears above the search bar like this: enter image description here

If you continue to drag it, it appears in the expected place, but if you click the view back while it is still refreshing, you will see the spinner on top of the search bar like this: enter image description here

As soon as you push it so that the rotator touches the title of the first section, the spinner will immediately disappear.

Here's what it should look like in Mail - under the search bar: enter image description here

I tried to fix this problem by simply making the spinner under the search bar so that it never appeared above the surface, but that didn't work. Oddly enough, this code caused the spinner to be invisible in the gray area above the table, and if you push it, an inscription appears in the search bar - exactly the opposite of what I would expect. Here is the code:

self.refreshControl.layer.zPosition = self.searchDisplayController.searchBar.layer.zPosition - 1;

How to prevent a spinner from appearing above the search bar when using a minimal style?

+4
4

, . "", . Prominent , . , , .

+1

UISearchBarStyleMinimal, backgroundImage . , .

private extension UISearchBar {
    private func setBackgroundColorWithImage(color: UIColor) {
        let rect = self.bounds
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        CGContextSetFillColorWithColor(context, color.CGColor)
        CGContextFillRect(context, rect);

        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        self.backgroundImage = image // here!
    }
}
+3

.

refreshControl.layer.zPosition -= 1
0
source

So, if this helps someone, I have the same problem, and a quick fix adds refreshcontrol as a subtask self.view instead of tableheaderview. This will add a controller above all others and you will be able to see it. On the other hand, I believe that you can completely fix y by setting it under the correct layer. ZPosition. But I did not have time to completely fix it.

[self.view addSubview:self.refreshControl];
-1
source

Source: https://habr.com/ru/post/1544956/


All Articles