Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UISearchBar作为键盘的一部分?_Iphone_Uinavigationcontroller_Uisearchbar - Fatal编程技术网

Iphone UISearchBar作为键盘的一部分?

Iphone UISearchBar作为键盘的一部分?,iphone,uinavigationcontroller,uisearchbar,Iphone,Uinavigationcontroller,Uisearchbar,我在底部工具栏上有一个UISearchBar。问题是一旦你点击键盘,键盘就会把它盖起来。我在想办法解决这个问题。我尝试将其添加到顶部,但由于我使用的是UINavigationController,因此出现了一些意外行为。(就像自定义视图中的UISearchBar一样,当键盘在屏幕上时,RightBarButtonitim会变长,不会恢复到原来的大小,当按下键盘时,整个导航栏会离开屏幕,因此在这种情况下,您甚至看不到正在键入的内容。) 因此,作为一种解决方法,我想我可以在工具栏的右下角有一个用于搜

我在底部工具栏上有一个UISearchBar。问题是一旦你点击键盘,键盘就会把它盖起来。我在想办法解决这个问题。我尝试将其添加到顶部,但由于我使用的是UINavigationController,因此出现了一些意外行为。(就像自定义视图中的UISearchBar一样,当键盘在屏幕上时,RightBarButtonitim会变长,不会恢复到原来的大小,当按下键盘时,整个导航栏会离开屏幕,因此在这种情况下,您甚至看不到正在键入的内容。)


因此,作为一种解决方法,我想我可以在工具栏的右下角有一个用于搜索的系统图标,然后当键盘弹出时,搜索栏可以是键盘的一部分,然后你可以看到你键入的内容。有人知道我会怎么做吗?谢谢

我看到了这个任务的几种解决方案。简言之,您创建了一个UISearchBar/UIToolbar,为
UIKeyboardWillShowNotification添加了观察者,当此通知触发时,您创建的UISearchBar/UIToolbar只需设置动画0.3秒。链接:


  • 来自苹果IOS版的HIG:

    在列表或列表中的索引上方显示搜索栏。用户期望 在这个位置找到一个搜索栏,因为他们已经习惯了 联系人和其他应用程序中的搜索栏。进行搜索 此位置中的条形图表示,当发生以下情况时,它不会妨碍用户 他们正在滚动列表或使用索引,但是 在需要时方便地提供

    也许在屏幕底部显示搜索栏并不是故意的;)

    将UISearchbar放置在自定义ViewController的顶部应该可以工作。
    也许可以分享一些代码?

    铍在正确的轨道上。这里有一些代码可以帮助您实现这一目标

  • 将搜索栏移出屏幕,以便在按下按钮之前看不到它
  • 注册键盘将显示通知
  • 按下按钮时,使搜索栏“成为第一响应者”
  • 将搜索栏从底部(视图外)移动到键盘上方(视图内)
  • //


    您如何将此应用于支持将手机侧向转动的应用程序?由于手机的分辨率不同,效果也不一样。
    //in viewDidLoad register for notifications
     [self registerForKeyboardNotifications];
    
    //in viewdidload hide the search bar
    CGRect rect = searchBar.frame;
    rect.origin.y = 480;
    searchBar.frame = rect;
    
    //own function register for keyboardwillshow
    - (void)registerForKeyboardNotifications
    {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    }
    
    
    //when button is pushed move the searchbar into view. you may have to play with the pixels a bit to make sure it lands on top, and flush
    
    - (void)keyboardWillShow:(NSNotification*)aNotification
    {
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    CGRect rect = searchBar.frame;
    rect.origin.y = 180; //adjust the 180 to get it to land where you want
    searchBar.frame = rect;
    [UIView commitAnimations];
    }
    
    
    //own function hide the search bar when the keyboard is dismissed
    - (void)keyboardWillHide:(NSNotification*)aNotification
    {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    CGRect rect = searchBar.frame;
    rect.origin.y = 480;
    searchBar.frame = rect;
    [UIView commitAnimations];
    
    }