UISearchDisplayDelegate how to remove this opaque view?

前端 未结 4 699
醉话见心
醉话见心 2021-01-16 16:41

how can i programmatically show/hide this opaque view from UISearchDisplayController?

\"enter

4条回答
  •  醉话见心
    2021-01-16 16:54

    Mmmm...quick answer. Not pretty but surely works

        #pragma mark UISearchBarDelegate
    
    // Displays a view to simulate the lose of focus
    - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    
      searchBar.showsCancelButton = NO;
      searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    
      UIButton *view1 = [[UIButton alloc] init];
      view1.frame = CGRectMake(0, 0, 320, MAX(480, self.tableView.contentSize.height));
      view1.alpha = 0.6;
      view1.tag = 2000;
      view1.backgroundColor = [UIColor blackColor];
      [view1  addTarget:self
                 action:@selector(removeView)
       forControlEvents:UIControlEventTouchUpInside];
      [self.tableView setScrollEnabled:NO];
    
      [self.tableView addSubview:view1];
      [view1 release];
    }
    
    /**
     *  Pop the view and the keyboard
     */
    - (void)removeView {
      UIView *v = [self.tableView viewWithTag:2000];
      v.hidden = YES;
      [v removeFromSuperview];
      [self.tableView setScrollEnabled:YES];
      [self.searchBar resignFirstResponder];
    }
    

    That view is showed when you're writing, so I guess you should use it at searchBarTextDidBeginEditing. If I'm wrong, use it when you start searching or whatever.

提交回复
热议问题