开发者

How does Mail app disable UISearchBar when in edit mode?

开发者 https://www.devze.com 2023-03-23 23:33 出处:网络
Using a 开发者_运维知识库SearchDisplayController and couldn\'t find any methods that would accomplish this?Try this when switching to Edit mode:

Using a 开发者_运维知识库SearchDisplayController and couldn't find any methods that would accomplish this?


Try this when switching to Edit mode:

self.searchDisplayController.searchBar.userInteractionEnabled = NO;
self.searchDisplayController.searchBar.alpha = .5;

Reverse with:

self.searchDisplayController.searchBar.userInteractionEnabled = YES;
self.searchDisplayController.searchBar.alpha = 1.0;

You can also animate the alpha change for extra credit :)


Check out the UISearchDisplayDelegate and the UISearchBarDelegate for knowing when the search bar is in edit mode.

Here is some code to add an overlay over the searchBar, which I've adapted from this example,

In your .h file,

@interface ...
{
    UIView *disableViewOverlay;
    ...
}

@property(retain) UIView *disableViewOverlay;

And in the .m file,

@synthesize disableViewOverlay;

...

-(void) disableSearchBar 
{
    self.disableViewOverlay = [[UIView alloc]
                           initWithFrame:CGRectMake(0.0f,0.0f,320.0f,44.0f)];
    self.disableViewOverlay.backgroundColor=[UIColor blackColor];
    self.disableViewOverlay.alpha = 0;

    self.disableViewOverlay.alpha = 0;
    [self.view addSubview:self.disableViewOverlay];

    [UIView beginAnimations:@"FadeIn" context:nil];
    [UIView setAnimationDuration:0.5];
    self.disableViewOverlay.alpha = 0.4;
    [UIView commitAnimations];
}

-(void) enableSearchBar 
{
    [disableViewOverlay removeFromSuperview];
    [searchBar resignFirstResponder];
}

You can adjust the alpha values until it appears the way you want it to.

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号