UISearchDisplayDelegate 如何删除这个不透明视图?

发布于 2024-10-28 19:38:20 字数 289 浏览 1 评论 0原文

我如何以编程方式从 UISearchDisplayController 显示/隐藏这个不透明视图?

在此处输入图像描述

可能在 searchDisplayControllerWillBeginSearchsearchDisplayControllerDidBeginSearch 我需要设置一些东西...但是什么?

谢谢。

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

enter image description here

Probably in searchDisplayControllerWillBeginSearch or searchDisplayControllerDidBeginSearch i need to set something... but what?

thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

慵挽 2024-11-04 19:38:20

使用UIKeyboardWillAppearNotification临时解决

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

OpaqueView 是一个 alpha = 0.8 的UIControl

- (void) keyboardWillShow {
  for( UIView *subview in self.view.subviews ) {
   if( [subview isKindOfClass:[UIControl class]] ) {
      UIControl *v = (UIControl*)subview;
      if (v.alpha < 1) {
        v.hidden = YES;
      }
    }
  }
}

我使用了这种ORRIBLE方法来临时解决问题......任何其他想法将不胜感激

谢谢。

Temporary solved using UIKeyboardWillAppearNotification.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

OpaqueView is an UIControl with alpha = 0.8.

- (void) keyboardWillShow {
  for( UIView *subview in self.view.subviews ) {
   if( [subview isKindOfClass:[UIControl class]] ) {
      UIControl *v = (UIControl*)subview;
      if (v.alpha < 1) {
        v.hidden = YES;
      }
    }
  }
}

I used this ORRIBLE way to temporary fix problem.... any other idea will be appreciated!

thanks.

少钕鈤記 2024-11-04 19:38:20

ELPSK给出的代码是当前的,但在 ios7及以上 中无效

在ios6和ios7中工作的代码如下

- 在ViewDidload中添加以下通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

在下面写入函数

- (void) keyboardWillShow {
      for( UIView *subview in self.view.subviews ) {
       if([subview  isMemberOfClass:[UIControl class]] ||
         ([[[subview  class] description] isEqualToString:@"UISearchDisplayControllerContainerView"])) {
          UIControl *v = (UIControl*)subview;
          if (v.alpha < 1) {
            v.hidden = YES;
          }
        }
      }
    }

注意:代码只有一个额外的条件

Code given by elpsk is current but will not work in iOS7 and above

Code working in both iOS6 and iOS7 is as below

- add below notification in viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

Write below function

- (void) keyboardWillShow {
      for( UIView *subview in self.view.subviews ) {
       if([subview  isMemberOfClass:[UIControl class]] ||
         ([[[subview  class] description] isEqualToString:@"UISearchDisplayControllerContainerView"])) {
          UIControl *v = (UIControl*)subview;
          if (v.alpha < 1) {
            v.hidden = YES;
          }
        }
      }
    }

NOTE : Code just have one extra condition as in iOS7 UIControl class become UISearchDisplayControllerContainerView,

谁许谁一生繁华 2024-11-04 19:38:20

其他答案不适合我。这个对我来说适用于 iOS7 和 iOS8。

for( UIView *subview in self.view.subviews ) {
    if([subview  isMemberOfClass:[UIControl class]] ||
       ([[[subview  class] description] isEqualToString:@"UISearchDisplayControllerContainerView"])) {
        for(UIView *subView2 in subview.subviews)
        {
            for(UIView *subView3 in subView2.subviews)
            {
                if (subView3.alpha < 1) {
                    subView3.hidden = YES;
                }
            }
        }
    }
}

如果您不需要 iOS7 支持,请不要再使用 searchDisplayController,因为它已被弃用。对于 iOS8,请使用 UISearchController 和 dimsBackgroundDuringPresentation
属性

参考: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UISearchController/index.html#//apple_ref/occ/instp/UISearchController/dimsBackgroundDuringPresentation

The other answers where not working for me. This one works for me on iOS7 and iOS8.

for( UIView *subview in self.view.subviews ) {
    if([subview  isMemberOfClass:[UIControl class]] ||
       ([[[subview  class] description] isEqualToString:@"UISearchDisplayControllerContainerView"])) {
        for(UIView *subView2 in subview.subviews)
        {
            for(UIView *subView3 in subView2.subviews)
            {
                if (subView3.alpha < 1) {
                    subView3.hidden = YES;
                }
            }
        }
    }
}

If you don't need support for iOS7 please don't use the searchDisplayController anymore because its deprecated. For iOS8 use the UISearchController and the dimsBackgroundDuringPresentation
Property

Ref: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UISearchController/index.html#//apple_ref/occ/instp/UISearchController/dimsBackgroundDuringPresentation

内心激荡 2024-11-04 19:38:20

嗯...快速回答。不太漂亮,但肯定有效

    #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];
}

该视图是在您编写时显示的,所以我想您应该在 searchBarTextDidBeginEditing 中使用它。如果我错了,请在开始搜索或其他任何事情时使用它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文