Always show UISearchbar

Asked 2 years ago, Updated 2 years ago, 33 views

How do I always display the UISearchbar at the front of the menu in the ViewController, like the iOS GoogleMap app?

The following is the image.
Before opening the menu After opening the menu

ios

2022-09-30 12:08

1 Answers

In UIViewController, the underlying View is usually the property view.
If you addSubview: something in this view, the view will be at the front.

In other words, the last view you addSubview: is the front page, but you may also trigger user events after the initial display of the screen.

Here, bringSubviewToFront: is the method that puts View at the forefront.
This method allows you to put the SubView on the front page of the View.

As a solution to the question, I suggest that you call the view property addSubview: when it is addedSubview:

First, replace the properties view of the subclass of the UIViewController with the following UIView subclass:(on xib, storyboard, loadView, etc.)

@interfaceMyView:UIView
// View you want to keep at the front
@property(nonatomic,weak)UIView*frontView;
@end

@implementation MyView
// addSubview—Called when done
- (void)didAddSubview: (UIView*)subview
{
    // put at the forefront of
    if(self.frontView){
        [selfbringSubviewToFront:self.frontView];
    }
}

@end

A View (UISearchbar in this case) desired to be placed at the front is then set to the property frontView of the class when generating.(See below)

[(MyView*)self.view setFrontView:searchbar];

This causes didAdSubview: to be called each time addSubview: is addSubview: of the configured ViewController, and the View set to frontView is at the forefront.


2022-09-30 12:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.